Exchange 2010/2013 CrossForest group Migration made easy

Mohammed HamadaAzure / Office 365 Integration engineer
CERTIFIED EXPERT
I am a senior IT consultant for Azure, Telecom, Messaging and collaboration and Infra. I have been in the IT sector since 15 years.
Published:
Updated:
In an Exchange Crossforest migration, the distribution groups can be a very complex operation that would cause loss of time, lots of issues and continued headaches if not solved in a timely manner.

I had to do a similar project so I created a script to ease this process.

In an Exchange Crossforest migration, the distribution groups can be a very painful operation that would cause loss of time, lots of issues and continued headaches if not solved in a timely manner. The migration can be a long and boring process that needs to be as accurate as possible to avoid any issues related to members of the group or/and Group’s Primary SMTP details.


While doing a Crossforest migration, I came through this headache and tried to seek a script that would satisfy my migration’s requirements but the only thing I found is the export Powershell made by Satheshwaran Manoharan.


Export Process:


The script exports all groups and their members from the source forest, but to import there’s no option and I had to write my own script. 


To make use of this script first make sure you that you have migrated the Groups with ADMT in the recommended order otherwise the migration would be problematic. 


  • First: Universal Groups 
  • Second: Global Groups 
  • Third: Domain Local Groups


Once groups are migrated to the target forest you can check how they look like through Exchange management shell and whether they have members added or SMTP address set.



After I checked it apparently shows that group is empty and has no Primary SMTP address associated with it.


Import Process:


In order to add members during the migration since this is a Hybrid/Coexistence migration, not cutover, It took time to migrate users and therefore I had to add non-migrated users in target forest as External Contacts to the Distribution Groups and add migrated users as Mailbox users.


Then after adding the users, I had to set up Primary SMTP addresses for the groups according to the exported CSV file from the Source Forest.



To Import users, I had to set up a CSV file with the following format:


In this format, the Display name, Alias, RecipientType and PrimarySMTPAddress belong to the User object that’s included in the group meanwhile, The Dgroup is the Distribution group’s Alias and DGSMTP is the Group’s Primary SMTP address.



The following script imports groups members to their relative groups


#########################################################################################
# If user type is Usermailbox then it’ll be in Target forest as a Contact #
#########################################################################################
$Users = Import-Csv “C:\Groups\dgs.csv”
Foreach ($User in $Users){
$GroupAlias = $User.Dgroup
$GroupSMTP = $User.DGSMTP
Write-Host “$User.Alias” has been Added to the Group $User.Dgroup -ForegroundColor Green -BackgroundColor Black
if ($User.RecipientType -Match “UserMailbox”){
Add-DistributionGroupMember -Identity $GroupAlias -Member $User.PrimarySMTP -BypassSecurityGroupManagerCheck}}


Fixing Distribution Groups Primary SMTP Address:


Since distribution groups are mostly imported without Primary SMTP address through ADMT then we’ll have to also make sure that we fix this for our groups, but what if the destination forest has similar groups or the SMTP is used already? 


In order to avoid any mistake when associating the Primary SMTP address, I have created a script that would check distribution groups with null value in their primary SMTP Address and copy the SMTP address to these groups avoiding any overwrite or change of the destination Distribution groups.


#########################################################################################
# Setup groups with Primary SMTP Address
#########################################################################################
$Groups = Import-Csv “C:\Groups\Group_test.csv”
Foreach ($Group in $Groups){
$GroupAlias = $Group.dgroup
$GroupSMTP = $Group.DGSMTP
if ((Get-DistributionGroup $GroupAlias | %{$_.PrimarySmtpAddress}) -match “$GroupSMTP”) {
Write-Host Group $GroupAlias already has $GroupSMTP Setup as primary SMTP address -ForegroundColor Yellow -BackgroundColor Red}else{
Set-DistributionGroup -Identity $GroupAlias -PrimarySmtpAddress $GroupSMTP -EmailAddressPolicyEnabled $False
Write-Host Group $GroupAlias has $GroupSMTP Setup as primary SMTP -ForegroundColor Green -BackgroundColor Black }}


The script will check if the groups have primary SMTP matches the one in the CSV file, if it doesn’t it’ll set up the primary SMTP address for that group with green color like in the screenshot below



You can use this script with the same CSV file that you will use for adding members to the groups too, If groups SMTP exists already you’ll get the following error



Hope this can be helpful to whoever is doing Exchange Crossforest Migration


0
948 Views
Mohammed HamadaAzure / Office 365 Integration engineer
CERTIFIED EXPERT
I am a senior IT consultant for Azure, Telecom, Messaging and collaboration and Infra. I have been in the IT sector since 15 years.

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.