Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Changing database recovery model


In this recipe, we will explore how to change SQL Server recovery model using PowerShell.

Getting ready

We will use AdventureWorks2014 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. Right-click on the database you chose, click on Properties, and select Options:

If your database is set to either Simple or Bulk-logged, change this to Full and click on OK. Since we will use AdventureWorks2014 in later exercises, we need to change this recovery model back to Full after this exercise.

How to do it...

The steps to change the recovery model are as follows:

  1. Open PowerShell ISE as administrator.

  2. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. Add the following script and run:

    $instanceName = "localhost"
    $server = New-Object -TypeName Microsoft...