Easy peasy script to turn off AutoShrink on all databases. I’ll let Paul Randal do the talking as to why you shouldn’t have autoshrink turned on.
Import-Module sqlps -DisableNameChecking $ignoreDBs = @('IgnoreDB') try{ gc -Path 'c:\Servers.txt' | %{ $srv = New-Object Microsoft.SqlServer.Management.Smo.Server $_ $srv.Databases | where{-not $_.IsSystemObject -and $_.Name -notin $ignoreDBs} | %{ if($_.AutoShrink -eq $true){ $_.AutoShrink = $false $_.Alter(); } } } } catch{ $srvName $_ | fl -Force } finally{ }
This is a great idea but the script doesn’t appear to work:
You must provide a value expression on the right-hand side of the ‘-‘ operator.
At C:\scripts\Turnoffautoshrink.ps1:8 char:69
+ $srv.Databases | where{-not $_.IsSystemObject -and $_.Name – <<<< notin $ignoreDBs} | %{
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression
Methinks you’re using a powershell version 1 or 2. -notin only works in version 3 and above.
Scott