Exchange 2010 CrossForest group Migration

In an Exchange Crossforest migration the distribution groups can be a very painful operation that would cause loss of time, lots of issues and continues headache if not solved within a timely manner.

The migration can be a long boring process that needs to be as accurate as possible to avoid any issue related to members in the group or/and Group’s Primary SMTP details.

While doing a Crossforest migration I came through through this headache and tried to seek a script that would satisfy my migration’s requirements but 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.

image

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 have 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 have to setup Primary SMTP address for the groups according to the exported CSV file from the Source Forest.

image

To Import users, I had to setup 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.

image

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 | {308b10a016e19a1cd6a208cbc3961927e16fc6766a4020d3c4ef54ea17925f0f}{$_.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 has primary SMTP matches the one in the CSV file, if it doesn’t it’ll setup the primary SMTP address for that group with green color like in the below screenshot

image

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

image


Get all mailbox Exchange Servers IP address remotely

Sometimes while we do Exchange projects in big environments where there more than 10 or 15 servers we need to quickly get a particular server’s hostname or IP.

I created a simple PowerShell script that does the work for you

#Get all mailbox Exchange Servers IP address remotely

#Import Exchange Management Shell if ran from PowerShell
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

# Find Mailbox Server Roles
$Servers = Get-ExchangeServer | Where-Object {$_.Serverrole -eq “mailbox”}

# Print Servername and IP
foreach ($Server in $Servers) {Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $Server | Select-Object -Property IPAddress,PsComputerName,Name}

image

Solving Deleted contacts problem after losing LegacyExchangeDN Address

So here is the story.

I was doing a cross forest project and one of the IT guys I was working with deleted the contacts and then all users in the target forest started complaining that they couldn’t send emails to the source forest users.

Once we got contacts back from the backup they came with a new LegacyExchangeDN address which resulted in failing again.

In order to solve the problem we had two options, First is to delete autocomplete for all users which was a very difficult option and hard to approve since there are more than 6000 users who will lose their Auto complete.

The other option was to get the old LegacyExchangeDN address from users’s outlook which was even more difficult but from a management point of view was the way to go.

Using NK2Editor with its commands I managed to configure Script through GPO to get all the Autocomplete files from users.

Steps are as following:

1- Create a shared folder on one computer that all users can access (Usually Sysvol would do the job). Or place the Nk2Editor in the sysvol folder and run the command against all users from there.

2- Using GPO create a script policy to convert the currently used Default Autocomplete file using Nk2Editor’s command capability into CSV file

.\NK2Edit.exe /ExportCharEncoding 1 /scomma “$env:USERNAME.csv”

3- Copy the CSV file to the shared folder (you can do this using Powershell as well).

4- Extract FullName and X500 columns from users’s CSV files into one file in order to apply it with the following script.

Import-CSV C:\username.csv | foreach{Set-MailContact -identity $_.Name -EmailAddresses @{add=$_.LegacyExchangeDN}}

The CSV file that you got with NK2editor should be filtered to include only Name (Display name) and the Email address (LegacyExchangeDN).

This should do the work. I hope it helps someone who is stuck in the same situation.