Monday, May 13, 2019
ShareGate Migration using Powershell
#--------------------------------------------------------------------------------
# ShareGate needs to be activated in the server where we wre running this script.
#--------------------------------------------------------------------------------
if ( (Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
Import-Module sharegate
if ($Host.Name -eq "Windows PowerShell ISE Host")
{
$ISE=$true
}
else
{
$ISE=$false
}
if (-Not $ISE)
{
$currentLocation = (Get-Location).Path
$logfile = $currentLocation + "\" + "LogFileNew_$(get-date -format `"yyyyMMdd_hhmmsstt`").csv"
Start-Transcript -Path $logfile
}
$startTime = Get-Date
Write-Host "Script started at :" $startTime
$csvFile = ".\Copy-Site.csv"
$farmAccount = "SHAREPOINT\system"
$counter = $null
$sites = Import-Csv $csvFile
$copysettings = New-CopySettings -OnContentItemExists IncrementalUpdate
foreach ($site in $sites)
{
$fileName = ".\Copy-SiteMigrationLogReport_" + $site.SNAME.Trim() + ".xlsx"
$copyGroupFile = ".\Copy-GroupLogReport_" + $site.SNAME.Trim() + ".xlsx"
try
{
#$mappingSettings = New-MappingSettings
$srcSite = Connect-Site -Url $site.Source.Trim()
Write-Host "Source Site : "$srcSite -ForegroundColor Yellow
$dstSite = Connect-Site -Url $site.Destination.Trim()
Write-Host "Destination Site : " $dstSite -ForegroundColor Green
$mappingSettings = Get-UserAndGroupMapping -SourceSite $srcSite -DestinationSite $dstSite
$mappingSettings = Set-UserAndGroupMapping -MappingSettings $mappingSettings -UnresolvedUserOrGroup -Destination $farmAccount
$copyGroupResults = Copy-Group -All -SourceSite $srcSite -DestinationSite $dstSite -CopySettings $copysettings -MappingSettings $mappingSettings
Export-Report $copyGroupResults -Path $copyGroupFile -Overwrite
$result = Copy-Site -Site $srcSite -DestinationSite $dstSite -Merge -CopySettings $copysettings -InsaneMode -MappingSettings $mappingSettings
Export-Report $result -Path $fileName -Overwrite
$siteCompTime = Get-Date
Write-Host "Site" $site.Source.Trim() " Migration Completed by :" $siteCompTime -ForegroundColor Green
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Red
}
}
$endTime = Get-Date
$totaltime=$endTime-$startTime
write-host -foregroundcolor Cyan "Total time taken for Script execution :"$totaltime
write-host -foregroundcolor Green "You are done!!! Sites Migration Completed at: " $endTime
if (-Not $ISE)
{
Stop-Transcript
}
Subscribe to:
Posts (Atom)