Home > PowerShell, SharePoint > PowerShell Script to loop through all the site collections and backup each Site

PowerShell Script to loop through all the site collections and backup each Site


Just change the backup location and script is ready to go.

#Add SNAP-IN

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}

if ($snapin -eq $null)

{

Write-Host “Loading SharePoint Powershell Snap-in”

Add-PSSnapin “Microsoft.SharePoint.Powershell”

}

#Loop through the web application and do a backup of each Site

Get-SPWebApplication | Get-SPSite | Get-SPWeb -Limit All | ForEach-Object{$FilePath = “C:\Backups\” + $_.Url.Replace(“http://”,””).Replace(“/”,”-“) + “.bak” ;

Export-SPWeb -Identity $_.Url -Path $FilePath -Force -NoFileCompression}

Advertisements
Categories: PowerShell, SharePoint
  1. November 21, 2012 at 3:26 am

    Why did you chose to use “Export-SPWeb” instead of Backup-SPWeb?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: