Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Special method for evaluating Database Properties through conditional statements?

$
0
0
Passing an Instance name for $Instance, this loops through all databases on the instance. Gathers their name and Recovery model. Writes the name and recovery model. However, the conditional statement always evaluates false, despite the database being in Full recovery Mode. Is there some special way to evaluate database properties?[code="plain"]$InstanceObject = New-Object (’Microsoft.SqlServer.Management.Smo.Server’) -argumentlist $InstanceName# loop through all databases within this instance$InstanceObject.Databases | foreach-object { # get database object into a variable $DatabaseObject = $_ $DatabaseName = $DatabaseObject.Name $RecoveryModel = $DatabaseObject.RecoveryModel write-host $DatabaseName $RecoveryModel if($RecoveryModel -eq "Full"){write-host "$DatabaseName is in $RecoveryModel recovery mode"} }[/code]

Viewing all articles
Browse latest Browse all 467

Latest Images

Trending Articles



Latest Images