
SharePoint migrations involve moving data from one SharePoint environment to another. This could be from an older version of SharePoint to a newer one, from on-premises to online, or from one site collection to another. Migrations are often necessary to take advantage of new features, improve performance, or consolidate sites. However, they can be complex and time-consuming, with a risk of data loss or corruption.
To ensure a successful migration, it’s crucial to verify that all data has been correctly transferred and nothing has been lost or corrupted. This is where a post-migration comparison report comes in handy.
Post-Migration Comparison Report with PowerShell
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
function PostMigrationComparisonReport($siteUrlSource, $siteUrlDestination)
{
$Cred= Get-Credential
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
$ctxSource = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrlSource)
$ctxSource.Credentials = $credentials
$ctxDestination = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrlDestination)
$ctxDestination.Credentials = $credentials
$webSource = $ctxSource.Web
$listsSource = $webSource.Lists
$ctxSource.Load($listsSource)
$ctxSource.ExecuteQuery()
$webDestination = $ctxDestination.Web
$listsDestination = $webDestination.Lists
$ctxDestination.Load($listsDestination)
$ctxDestination.ExecuteQuery()
Write-Host -ForegroundColor Yellow "The site URL is" $webSource.Title
Write-Host -ForegroundColor Yellow "The dest site URL is" $webDestination.Title
$tableListNames =@()
$destinationListsDict = @{}
foreach ($listDestination in $listsDestination)
{
$destinationListsDict[$listDestination.Title] = $listDestination
}
foreach ($listSource in $listsSource)
{
Write-Host -ForegroundColor Yellow "List name: " $listSource.Title
$o = @{
"sListName" = $listSource.Title
"sNo. of Items" = $listSource.ItemCount
"sLastItemModifiedDate" = $listSource.LastItemUserModifiedDate
"dListName" = "NotSet"
"dItemsCount" = "NotSet"
"dLastItemModifiedDate" = "NotSet"
}
if ($destinationListsDict.ContainsKey($listSource.Title))
{
$listDestination = $destinationListsDict[$listSource.Title]
Write-Host -ForegroundColor Green "List name: " $listDestination.Title
$o["dListName"] = $listDestination.Title
$o["dItemsCount"] = $listDestination.ItemCount
$o["dLastItemModifiedDate"] = $listDestination.LastItemUserModifiedDate
}
$tableListNames += $o
}
return $tableListNames
}
The provided PowerShell script generates a post-migration comparison report between two SharePoint sites. It’s particularly useful when you’ve migrated content from one SharePoint site to another and you want to verify that the migration was successful.
The script defines a function PostMigrationComparisonReport that takes two parameters: the source site URL and the destination site URL.
The function prompts for credentials using Get-Credential and creates a SharePoint Online credentials object. It then creates ClientContext objects for both the source and destination SharePoint sites.
The script fetches the Web objects and the Lists objects for both sites. It then prints the titles of the source and destination sites and initializes an empty array $tableListNames to store the comparison data.
The script then loops through each list in the source site, prints the list name, and creates a new PSObject to store the list details. For each list in the source site, it loops through each list in the destination site. If it finds a list with the same title, it updates the PSObject with the details of the list from the destination site.
The PSObject is then added to the $tableListNames array. Finally, the function returns the $tableListNames array which contains the comparison data for all the lists in the source and destination sites.
Function call
Now, execute the function PostMigrationComparisonReport, passing the source and destination site URLs as parameters:
PostMigrationComparisonReport "https://MsTalk.sharepoint.com/MsTechTalkSource" "https://MsTalk.sharepoint.com/sites/MsTechTalkDestination" | Out-GridView
Alternatively, export the output as a CSV file to enable Excel viewing capabilities:
PostMigrationComparisonReport "https://MsTalk.sharepoint.com/MsTechTalkSource" "https://MsTalk.sharepoint.com/sites/MsTechTalkDestination" | ExportCsv -Path "C:\ PostMigrationComparisonReport.csv"






No Comments