So, when I started my 2nd Job one of the main tasks was to migrate all the users from Exchange 2010 to the O365. Once all of that was completed, I planned on removing Exchange, however I found that it is recommended to keep at least 1 Exchange server to run Exchange commands to if you plan to keep your AD on Prem. If you live on the wild side. You can edit AD attributes manually / script to create users, and have DIRSync/ADConnect pick it up. But that would be a hassle, instead of just doing a New-RemoteMailbox command. So I built an Exchange 2016 Box using the Hybrid License, and decommed the others. At the time I was on CU7. The problem I was having is that the New-RemoteMailbox command did not have an option to create shared mailboxes directly to the cloud. So I had to create a normal mailbox and convert it or create the SharedMailbox on Prem and migrate it. However, I found out in the later CUs they added a parameter to allow Creation of Shared Mailbox directly to the cloud.
Note: This switch is available only in Exchange 2013 CU21 or later and Exchange 2016 CU10 or later. To use this switch, you also need to run setup.exe /PrepareAD. For more information, see KB4133605.
This is a Function I created for our O365 Admins to quickly create a mailbox, and also a group to assign the users that need Full/SendAS access to the mailbox. I might have some other proprietary code such as removing the internal domain, but you can comment that stuff out if needed, but it shouldn’t hurt if it stayed in there.
Function New-SharedMailbox { Param ( [Parameter(Mandatory = $true)] [String]$Name, [Parameter(Mandatory = $true)] [String]$DisplayName, [Parameter(Mandatory = $true)] [String]$OwnerEmail ) $EmailAddress = $Name + '@Tenant.org' $MBCheck = Get-Recipient $EmailAddress -ErrorAction SilentlyContinue $Replace = '@tenant.int' If ($MBCheck) { Write-Host "EmailAddress Is already in Use Please use a different Name" } Else { $RoutingAddress = $EmailAddress -replace ("Tenant.org", "Tenant.mail.onmicrosoft.com") Do { $RoutingAddressCheck = Get-Recipient $RoutingAddress -ErrorAction SilentlyContinue if ($RoutingAddressCheck) { [String]$RandomNumber = (10 .. 100) | Get-Random [String]$RoutingAddress = $Name + $RandomNumber + '@Tenant.mail.onmicrosoft.com' } $RoutingAddressCheck = Get-Recipient $RoutingAddress -ErrorAction SilentlyContinue } Until($RoutingAddressCheck -eq $Null) Write-Host "Enabling $Name to Cloud" New-RemoteMailbox -Alias $Name -OnPremisesOrganizationalUnit "OU=Email,OU=Accounts,DC=tenant,DC=int" -shared -RemoteRoutingAddress $RoutingAddress -userprincipalname $EmailAddress -PrimarySmtpAddress $EmailAddress -DisplayName $DisplayName -name $Name Write-Host "waiting on AD Replication 30 Seconds" Sleep 30 $ProxyAddresses = (Get-ADUser $Name -Properties ProxyAddresses).ProxyAddresses Foreach ($ProxyAddress in $ProxyAddresses) { If ($ProxyAddress -like "*tenant.int*") { Write-Host "Removing $Replace from $Name" Set-ADUser $Name -Remove @{ Proxyaddresses = $ProxyAddress } } } $GroupName = $Name + '-OW' $GroupEmail = $GroupName + '@Tenant.org' Write-Host "Creating Group $GroupName" New-DistributionGroup -Name $GroupName -PrimarySmtpAddress $GroupEmail -ManagedBy $OwnerEmail -RequireSenderAuthenticationEnabled:$True -CopyOwnerToMember:$True -OrganizationalUnit "OU=USG,OU=Email,OU=Accounts,DC=tenant,DC=int" -Type Security Write-Host "Hiding From Address List" Sleep 15 Set-DistributionGroup $GroupName -HiddenFromAddressListsEnabled:$True Write-Host "All Done.. Make sure to add the group with full / sendas on O365 after 30 min Sync" -ForegroundColor Green } }