Pages

Friday, February 8, 2013

Powershell Script for back and Resote Site Collections

Recently I had to backup a whole bunch of Sites in SharePoint and move it to a new site collection. There is powershell command to backup and restore the site or site collection which is what i used but there were 100 sites that needs to be moved. I decided to quickly put together a script that can loop and copy all the available site in SharePoint.

Similarly I created the Restore script that copies the site backup to the new site collection. I am sharing this here hoping someone will benefit and not have to invent the wheel over and over again.



Back up Script

$mysitesurl = "http://vsspsandbox/my/*"
$backuppath = "c:\backup\mysitebackup."
$webapp = "http://vsspsandbox/"
Get-SPSite -WebApplication $webapp -Limit ALL | where { $_.Url -like $mysitesurl } | ForEach-Object{ $path = $backuppath + $_.Url.Substring($_.Url.LastIndexOf("/")+1); Backup-SPSite -Identity $_.Url -Path $path -Verbose }


No comments:

Post a Comment