I have a requirement to export all sites with in site collection to a separate backup file. With lots of sub-sites I thought the best way to do this would be with a PowerShell script that utilises the Export-SPWeb command. So I wrote one! Here is the script:
<#
--------------------------------------------
SharePoint 2010 PowerShell script to export
all sites within a given Site Collection to
a separate file.
File : ExportSites.PS1
Revision history:
-----------------
1.0 Initial version
---------------------------------------------
#>
# -------------
# Set variables
# -------------
$SiteCollection = "http://intranet"
$sites = Get-SPWeb -Site $SiteCollection -Limit All
$ExportFolder = "D:\Exports\"
# ------------
# Begin export
# ------------
ForEach ($site In $sites)
{
$ExportFile = $ExportFolder + $site.Title + ".cmp"
Write-Host "Exporting" $site.title "-" $site.url
Export-SPWeb $site.url -Path $ExportFile -IncludeVersions All -IncludeUserSecurity -Force
Write-Host "Export to" $ExportFile " complete. File is" (Get-Item $ExportFile).length "bytes." -ForegroundColor "Green"
}
And here is a screenshot of the output, colour coded to make it easier to read:
Feel free to copy the code and use the script as you see fit (at your own risk of course, I can not and will not take responsibility for any undesired outcome). You may wish to add additional parameters to the Export-SPWeb command such as UseSQLSnapshot, or NoLogFile
No comments:
Post a Comment