Changing database recovery model
In this recipe, we will explore how to change SQL Server recovery model using PowerShell.
Getting ready
We will use AdventureWorks2008R2 in this exercise, and change the recovery model from Full
to Simple
. Feel free to substitute this with a database of your choice.
Check what SQL Server recovery model your instance is set to, using SSMS. Open your Object Explorer and right-click on the database you chose and click on Properties | Options:
If your database is set to either Simple or Bulk-logged, change this to Full and click on OK. Since we will be using AdventureWorks2008R2
in later exercises, we need to change this recovery model back to Full after this exercise.
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
Add the following script and run:
$instanceName = "KERRIGAN" $server = New-Object...