SP2010: Exporting site subscriptions in multi tenant setup

I created this little script I wanted to share, which loops though a web application; finds all site subscriptions (for multitenancy) and exports both the sites in there and the settings of the subscription. You could use the result to import the sites again into a test environment (for instance).

$url = "http://contoso.com"
$share = "\\server\backup\"

$wa = Get-SPWebApplication $url

foreach ($sub in $wa.SiteSubscriptions)
Write-Host Exporting site subscription $sub.Id

# create the folder (skipped when it exists
$folder = $share + $sub.Id
if(!(test-path $folder -pathtype container))
New-Item -Path $folder -ItemType directory

$exportPath = $folder + "\subscriptionsettings.bak"
Export-SPSiteSubscriptionSettings $sub -Path $exportPath -Force

foreach ($site in $sub.Sites)
Write-Host Exporting site $site.Id
$backupPath = $folder + "\" + $site.Id + ".bak"
Backup-SPSite $site -Path $backupPath -Force

There are some other scripts out there which use Get-SPSiteSubscription -ReturnSites, but that parameter doesn’t exist in my environments. I think it might be a left over from the beta phase. Also that script you would have to use per subscription, the script above works per web application. And with one more foreach-loop, you could run it across all webapplications too.

, ,

Related posts

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *