Oftentimes our customers need to automate migration of multiple SharePoint site collections, sites or libraries. Well, you can easily generate corresponding command lines in the Migration Suite UI and put them to a CMD or PowerShell script (see part 1 on using Migration Suite command line from PowerShell) and schedule it to run at a desired time.
But would not it be better to create a single reusable script that can take a list of source and target URLs from, say, a text file and copy your sites or libraries consistently?
I know it would and this is exactly what I want to show in today's post.
My sample site copy PowerShell script below takes source and target site URLs from a simple 2-column CSV file ($CSVInput). Then it just loops through the list and invokes the site copy command (-cmd copysite) with some common options. The rest of the script should be pretty self-explanatory, except for the strange format of the line that invokes the application. See the blog post I mentioned above for clarification.
One final note. The script is copying source sites to existing target sites. If you need to copy as new subsites, you will need to adjust the command line accordingly. So you will want to include the -asnewsite switch and other required options. Again modeling your command line from a auto-created command line in the application UI is your best bet.
## Dell installation path
$DellPath = "C:\Program Files\Dell Software\Migration Suite for SharePoint\dell"
## User name
$User = "CONTOSO\administrator"
$Pwd = "XXXXX"
## Log File
$Log = "C:\Script\Site Copy\log.xml"
## CSV file with source/target URLs
$CSVInput = "C:\Script\Site Copy\sites.csv"
$Jobs = import-csv $CSVInput
foreach ($Job in $Jobs)
$SrcWeb = $Job.Source
$TrgWeb = $Job.Target
Write-Host "Migrating $SrcWeb now"
& "$DellPath\jre\bin\java.exe" -jar $DellPath\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar -cmd copysite -srcsite $SrcWeb -trgtsite $TrgWeb -srcuser $User -srcpass $Pwd -trgtuser $User -trgtpass $Pwd -overwritebehavior dont_copy -copysubsites -copycontenttypes -copylists -copylistcontent -copylisthistory -authorship basic -copywebparts -log $Log -noSplash >output.txt 2>&1
As always, you can find the scipt attached to this post for your convenience.