Set Database Recovery Model using Powershell

Another quick script to set all database recovery models using powershell.  This ignores system databases.  This uses sqlpsx as well.

Import-Module SqlServer

$dataBases = Get-SqlDatabase -sqlserver "ServerName" | where{$_.IsSystemObject -ne $true}
foreach($db in $dataBases)
{
	if($db.RecoveryModel -eq [Microsoft.SqlServer.Management.Smo.RecoveryModel]::BulkLogged)
	{
		$db.RecoveryModel = [Microsoft.SqlServer.Management.Smo.RecoveryModel]::Simple;
		$db.Alter();
	}
}
Advertisements

One Comment on “Set Database Recovery Model using Powershell

  1. Hi There,

    I need to run this script on multiple servers remotely.
    Is there a way for the script to get a serverlist.txt or .csv with all the remote servers in it and run it on them?

    Kindest Regards,,
    Chris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: