To Export Specific OU for example to Enable Remote mailboxes
Get-ADuser -SearchBase "Distingushedname" -filter * | Select-Object samaccountname,userprincipalname | Export-csv userdump.csv
Take CSV and replace user principal name with remote routing address. if you wish to populate remote mailboxes for a specific Organizational Unit. Make sure you replace it with your appropriate remote routing address specific to your Office 365 tenant.
Import-Csv EnableRemoteMailboxes.csv | ForEach-Object{new-RemoteMailbox -Identity $_.samaccountname -remoteroutingaddress $_.userprincipalname}
Use the Attached CSV. Fill with samaccountname and enable archive mailboxes in bulk
Import-Csv accounts.csv | ForEach-Object{Enable-RemoteMailbox -Identity $_.samaccountname -Archive}
Always specify remote routing address while enabling remote mailboxes otherwise powershell will throw up the below error.
The error – for the purposes of people searching for it is The Address @tenantname.mail.onmicrosoft.com is invalid: “@tenantname.mail.onmicrosoft.com” isn’t a valid SMTP address. The domain name can’t contain spaces and it has to have a prefix and a suffix, such as example.com. FullyQualifiedErrorID : F0109C5E,Microsoft.Exchange.Management.Recipient.Tasks.EnableRemoteMailbox.