I have the following code which works:
foreach ($db in $svr.Databases |
where-object {
$_.name -eq "testDB"
-or $_.name -eq "master"
-or $_.name -eq "model"
-or $_.name -eq "msdb" } )
{
write-output $db.name
}
Is a cleaner way to do this?
Something like:
foreach ($db in $svr.Databases |
where-object {$_.name -in "testDB, master, model, msdb" } )
{
write-output $db.name
}
Use the
-containsoperator. Like:Use
help about_Comparison_Operatorsto learn more about this and other comparison operators.Update:
PowerShell v3 has added the
-inoperator. The example in the original question will work in v3.