Lately there have been a few discussions in the support forums asking about how to compare the number of items in the source mailbox to the number of items in the Microsoft Exchange Online mailbox following a migration. We decided to develop this quick script which you feed a list of users and it will compare the number of items in each folder of their Microsoft Online mailbox to the number of items in each folder in their local Exchange mailbox. If there is a difference between a folder, or if the folder doesn’t exist on Microsoft Online, it will let you know. The output CSV file looks like:

Name,SourceItemCount,TargetItemCount
[email protected] 1”,491,114
[email protected] 9”,491,100
[email protected],14888,3547
[email protected] Issues”,0,”Not Found in Target Mailbox”
[email protected] Issues/Conflicts”,0,”Not Found in Target Mailbox”
[email protected] Issues/Local Failures”,0,”Not Found in Target Mailbox”
[email protected] Issues/Server Failures”,0,”Not Found in Target Mailbox”
[email protected] Items/Test”,1,”Not Found in Target Mailbox”

You can download the properly formatted version of the script here. If you have any questions or need assistance, please contact us.

##############################################################################
#Microsoft Online Mailbox Migration Validation Script
#
#Written By:Chad Mosman, MessageOps, www.messageops.com
#
#This script compares the number of items in the source mailbox to the
#number of items in corresponding target mailbox. If them the number of
#items is different, or if a source mailbox folder is not present in the
#target mailbox, the information is written to a .csv file. In the CSV file
#the user's email address is appended to the folder name, for example:
#
[email protected]
#
#The following variables should be modified prior to running the script.
#
#The path to a file containing the users that have been migrated.
#You must have a header row named mail in the file. Then you'll just
#need one email address per line.
$userlist = "c:\migration\userlist.csv"

#The name of the source mailbox server
$Sourceserver ="Exchange.domain.local"

#The admin username for the source mailbox server
$SourceUser = “Domain\administrator”

#The admin password for the source mailbox server
$SourcePass = “Password”

#The name of the Microsoft Online Server
$targetserver = “red001.mail.microsoftonline.com”

#The admin username for Microsoft Online
$TargetUser = “[email protected]

#The admin password for Microsoft Online
$TargetPass = “Password”
##############################################################################

$sourcepassword = ConvertTo-SecureString $SourcePass -AsPlainText -Force
$sourcecred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $SourceUser,$sourcepassword

$Targetpassword = ConvertTo-SecureString $TargetPass -AsPlainText -Force
$targetcred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $TargetUser,$targetpassword

[email protected]()

import-csv $userList | foreach {

$sourcembx = Get-XsHostedExchangeMailbox -SourceServer $sourceserver -sourceidentity $_.mail -sourceadmincredential $sourcecred -sourcedetail full

$targetmbx = Get-XsHostedExchangeMailbox -SourceServer $targetserver -sourceidentity $_.mail -sourceadmincredential $targetcred -sourcedetail full

$ID = $_.mail

$sourcembx.folders | ForEach-Object {
$Folderobj= “” | select Name,SourceItemCount,TargetItemCount
$Matched = 0
$SourceFolderName = $_.displayname
$SourceItemCount = $_.ItemCount
$targetmbx.folders | ForEach-Object{
if ($SourceFolderName -eq $_.displayname){
$Matched = 1
If ($SourceItemCount -ne $_.itemcount){
#Write-host $sourcefoldername , $sourceitemcount , $.displayname , $.itemcount
$Folderobj.Name = $ID + “-” + $sourcefoldername
$Folderobj.SourceItemCount=$sourceitemcount
$Folderobj.TargetItemCount=$_.itemCount
$foldercollection += $folderobj
}
}
}
If ($Matched -eq 0){
#Write-Host $Sourcefoldername , “not found in Target mailbox”
$Folderobj.Name = $ID + “-” + $sourcefoldername
$Folderobj.SourceItemCount=$sourceitemcount
$Folderobj.TargetItemCount=”Not Found in Target Mailbox”
$foldercollection += $folderobj
}
}

}

 

$foldercollection | Export-Csv "MailboxCompare-$((Get-Date -uformat %Y%m%d%H%M%S).ToString()).csv" -NoTypeInformation

Was this article helpful?
YesNo