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{
}
Leave a reply to Scott Newman Cancel reply