To restore an SQL Server 2008 database, I would lile to be able to just do something like this in powershell:

./restore.ps1 DatabaseName.bak

Then the powershell script would by convention restore it to a database with name "DatabaseName". It would disconnect any user connected to this database so that it can restore the DB. It would store the mdf and ldf in the default location.

This would mainly be while developing on my personal machine. Just a quick way to restore a DB.

Anyone has such a script?

Thanks

link|improve this question
If you're familiar with ADO.NET it isn't hard to create some wrappers around SqlConnection/SqlComment to set up parameters from a hash and then call ExecuteNonQuery. – Richard Feb 27 '11 at 10:51
feedback

1 Answer

up vote 3 down vote accepted

I created a script and posted it on PoshCode which should meet your requirements. The script uses the SQLPSX sqlserver module. Note I had to add a restore file list only option to the invoke-sqlrestore function, so you'll need to grab the module from source code section rather than download section. This will be added to a future release of SQLPSX:

Module: http://sqlpsx.codeplex.com/SourceControl/changeset/view/58378#564810

Script: http://poshcode.org/2530

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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