Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a script to restore a SQL Server 2005 backup. Ideally the script will have the following features

  • handle backup files on a network location
  • Handle different file structure of source and destination server ("With MOVE"?)
  • Written in PowerShell

Any suggestions?

share|improve this question
I'm curious why you want to use PowerShell to run a SQL Command, when the Native T/SQL command will probably be easier to find and use? – mrdenny Aug 3 '09 at 19:33

Here's a link to a script I created

share|improve this answer

I'm using link text. Ok, is not really a Powershell script. But it works on all Servers, 2000 or 2005 so far. And it does a great job for me. Just executing master..usp_build_restore_script and copy the relevant part for the Restore.

I did also an extension in Powershell. As a sample, before i execute a Restore, i like to see if the necessary files really exists or not. For this i just execute the master..usp_build_restore_script from Powershell and use test-path on all Backupfiles.

share|improve this answer

Not sure about the different structures but this post at should be agood starting point for you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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