I need a PowerShell script which could perform the following:

  • How to Back up and Content Database of a Web Application
  • Restore a Content Database on a newly created Web Application
  • and what is your question ?
    – Steve B
    Commented Jun 26, 2012 at 14:42
  • I need a PowerShell script which could handle both of above things :)
    – Geek
    Commented Jun 26, 2012 at 14:55
  • 2
    this is still not a question. Anyways, Why don't you simply detach DB from the source app, then reattach the DB to the target APP (backup the ocntent database in SQL server first)
    – Steve B
    Commented Jun 26, 2012 at 14:57
  • Because Steve B's comment bears repeating: quickmeme.com/meme/3pvcw2 Commented Jun 26, 2012 at 15:17
  • 2
    Don't be afraid to bing or browse TechNet for the standard powershell commands. Commented Jun 26, 2012 at 16:35

2 Answers 2


If both web apps are in the same farm, the fastest and easiest way is to detach DB from app A and reattach DB from B.

$srcApp = Get-SPWebApplication http://app1
$targetApp = Get-SPWebApplication http://app2

$dbs = Get-SPContentDatabase -WebApplication $srcApp  | % { $_.Name }

Get-SPContentDataBase -WebApplication $srcApp | Dismount-SPContentDataBase


$dbs | % { Mount-SPContentData -Name $_ -WebApplication $targetApp }

This script should do the job (can't test by now, don't fire it blindly).

[Edit] and of course, backup the whole content database before


Using the SharePoint PowerShell console

Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential} -Item <WebApplicationName> [-Verbose]

See this MSDN article: Use Windows PowerShell to back up a Web application in SharePoint Server.

Use this command to restore a content DB:

Restore-SPFarm -Directory <Backup folder name> -RestoreMethod Overwrite -Item <Content database name> [-BackupId <GUID>] [-Verbose]

See this TechNet article: Use Windows PowerShell to restore a SharePoint content database.

Please ensure that you understand these commands and run tests to know what is going to happen. Other links:




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.