PowerShell script to export all sites in a site collection to a seperate file
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
Author : David Webb
Date : 01/10/2013
Version : 1.0
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
![[BlogBookmark]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/blogbookmark.png)
![[Blogsvine]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/blogsvine.png)
![[del.icio.us]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/facebook.png)
![[Furl]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/furl.png)
![[Google]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/google.png)
![[LinkedIn]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/linkedin.png)
![[MySpace]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/myspace.png)
![[Reddit]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Twitter]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/email.png)
Awesome script dude, very useful!