Forum Discussion
SASK2381
Mar 15, 2020Copper Contributor
Migrating on prem disribution group to exchange online - Hybrid
* Hybrid setup (Exchange 2013 - Single Server) * All users already migrated to EXO * its time to migrate distribution groups (Almost 200) - Already synced using AAD * At present IT is controlli...
SASK2381
Mar 15, 2020Copper Contributor
CloudHal Thanks for response,
yes that's true right now , but we want to get rid of on-prem exchange . Do you think it will work fine when we turn off on-prem exchange server ? and we just able to manage them from AD ?
CloudHal
Mar 15, 2020Iron Contributor
What you are suggesting is possible but unsupported. You can manage email attributes using AD users and computers, but it is not so easy for support, and user accounts won’t have all the correct email attributes. For example managing proxy addresses is prone to error.
The only way of retaining AD at the moment is to also retain exchange for management.
The only way of retaining AD at the moment is to also retain exchange for management.
- SASK2381Mar 16, 2020Copper Contributor
CloudHal thanks,
so if I want to get rid of on-prem exchange , the only option is to recreate them all in EXO, in that case what is the best method, script, best practice to follow ?
Manually deletion and recreating is time consuming and also temporary disruptive as I have almost 200 Distributions group.
- Gregory HallMar 17, 2021Copper Contributor
######## Global Variables ############ Set-Location -Path $env:USERPROFILE\Documents #Get-PSSession | Remove-PSSession $UserCredential = Get-Credential $ListOfGroupsToMigrate = Import-csv .\GroupMigration.csv ####################################### $ListOfGroupsToMigrate | ForEach-Object { $SingleGroupToMigratePSMTP = $_.GroupEmailAddress $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EXCHSVRFQDN.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential Import-PSSession $Session -Allowclobber $distrotomovedetails = Get-DistributionGroup -Identity $SingleGroupToMigratePSMTP $distrotomovedetails | Export-csv .\singlegroupdetailsbeforedelete.csv -NoTypeInformation $distrotomovedetails | ForEach-Object{ $DistributionGroupName = $_.PrimarySmtpAddress Get-DistributionGroupMember -Identity $DistributionGroupName | ForEach-Object{ [PSCustomObject]@{ DistributionGroup = $DistributionGroupName MemberName = $_.DisplayName EmailAddress = $_.PrimarySmtpAddress #Other recipient properties here } } } | Export-csv .\GroupmembersBeforeDel.csv -NoTypeInformation ######################################### $groupowner = $distrotomovedetails.ManagedBy $GroupOwnerCorrected = $groupowner.split('/')[-1] $GroupOwnerCorrected.ToString() $Managedby = Get-ADuser -Filter "displayName -eq '$GroupOwnerCorrected'" $distrotomovedetails | fl # Extract All Email Addresses for single group one per line so you can easily add back in EXO $addresses = @() Foreach ($mbx in $distrotomovedetails) { Foreach ($address in $mbx.EmailAddresses) { $obj = "" | Select-Object Identity,Alias,EmailAddress,RecipientType $obj.Alias = $mbx.Alias $obj.Identity = $mbx.Identity $obj.RecipientType = $mbx.RecipientType $obj.EmailAddress = $address.ToString().SubString(0) $addresses += $obj } } $addresses | Export-Csv .\SingleDistroGroupsmtpaddresses.csv -NoTypeInformation $addresses #Remove OnPremises Group Remove-DistributionGroup -Identity $distrotomovedetails.Identity -Confirm:$false -Verbose Start-Sleep 120 #Create On-Premises Contact $ExternalEmailAddress = $distrotomovedetails.Alias + "@TENANT.mail.onmicrosoft.com" New-MailContact -DisplayName $distrotomovedetails.DisplayName -Alias $distrotomovedetails.Alias -ExternalEmailAddress $ExternalEmailAddress -OrganizationalUnit "OU=Contacts,OU=Exchange Accounts,DC=lge-mdr,DC=com" Set-MailContact -Identity $distrotomovedetails.PrimarySmtpAddress -HiddenFromAddressListsEnabled $true #Close Session with OnPremise Exchange Get-PSSession | Remove-PSSession -Verbose #Connect EXO Import-Module ExchangeOnlineManagement Connect-ExchangeOnline -Credential $UserCredential Write-Host -ForgroundColor Cyan "Running AAD Connect Sync" #Remotely Run AAD Connect Delta Sync $session = New-PSSession -ComputerName AADConnectSVRFQDN.com Invoke-Command -Session $session -ScriptBlock {Import-Module -Name 'ADSync'} Invoke-Command -Session $session -ScriptBlock {Start-ADSyncSyncCycle -PolicyType Delta} Remove-PSSession $session #Pause until AAD Connect Sync can run and Azure AD to catch up Write-Host -ForgroundColor Green "Pausing for AAD Connect to run and then we check EXO for the group" function Start-Sleep($seconds) { $doneDT = (Get-Date).AddSeconds($seconds) while($doneDT -gt (Get-Date)) { $secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds $percent = ($seconds - $secondsLeft) / $seconds * 100 Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining $secondsLeft -PercentComplete $percent [System.Threading.Thread]::Sleep(500) } Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining 0 -Completed } Start-Sleep 200 Write-host -ForegroundColor Cyan "Verifing the group is gone from Azure AD, command will proceed once group is not showing in EXO" $distrotomovedetails.PrimarySmtpAddress while($GetDistroFinder -ne $null){ Write-Host -ForegroundColor Cyan "Checking EXO for the old synced Distro Group" $GetDistroFinder = Get-DistributionGroup -Identity $distrotomovedetails.PrimarySmtpAddress Start-Sleep 10 } Write-Host -ForegroundColor Green "Group Appears to have been removed please verify on Azure AD" Read-Host -Prompt "Hit Enter To Proceed" ############ Recreate Group in the cloud ########################################################################################################################################### Write-Host -ForegroundColor Cyan "Recreating the group in EXO" #Create the EXO Distro group New-DistributionGroup -DisplayName $distrotomovedetails.DisplayName -Alias $distrotomovedetails.Alias -Name $distrotomovedetails.Name -MemberDepartRestriction $distrotomovedetails.MemberDepartRestriction -MemberJoinRestriction $distrotomovedetails.MemberJoinRestriction -PrimarySmtpAddress $distrotomovedetails.PrimarySmtpAddress -RequireSenderAuthenticationEnabled:$false -ManagedBy $Managedby.UserPrincipalName -Verbose #Add additional SMTP and x500 addresses to the group. Write-Host -ForegroundColor Green "Adding SMTP and x500 Addresses Back to" $distroprimarysmtp $EmailAddressesToAdd = Import-Csv .\SingleDistroGroupsmtpaddresses.csv $EmailAddressesToAdd | ForEach-Object { $AliasOfGroup = $_.Alias $AddressToAdd = $_.EmailAddress $x500 = "x500:"+ $distrotomovedetails.LegacyExchangeDN $GroupLookup = Get-DistributionGroup -Identity $AliasOfGroup Set-DistributionGroup -Identity $GroupLookup.Identity -EmailAddresses @{Add=$AddressToAdd} -Verbose } #Add Group Members Back to Group Write-Host -ForegroundColor Magenta "Adding Members Back to Group" $GroupMembers = Import-Csv .\GroupmembersBeforeDel.csv $GroupMembers | ForEach-Object { $Distroprimarysmtp = $_.DistributionGroup $MemberPrimarySMTP = $_.EmailAddress Write-Host "Adding $memberprimarysmtp to $Distroprimarysmtp" Add-DistributionGroupMember -Identity $Distroprimarysmtp -Member $MemberPrimarySMTP } #Confirm Group Get-DistributionGroup $distroprimarysmtp | Select Alias,PrimarySmtpAddress,ManagedBy,IsDirsynced,WhenCreated | FT }