Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created May 19, 2015 12:32
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wpsmith/4c7d0c7209da0a55f1ec to your computer and use it in GitHub Desktop.
PowerShell: Set AutoGrowth for SQL Server cycling through the individual filegroups as well as excluding system databases.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
$server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "localhost"
$databases = $server.Databases;
foreach ($db in $databases ) {
#Set Log File growth
if ($db.Status -eq 'Normal' -and -$db.IsSystemObject -eq $false) {
$l = $db.LogFiles[0]
$l.GrowthType = "KB"
$l.Growth = "51200"
$l.Alter();
$df = $db.FileGroups
foreach($fg in $df){
foreach ($f in $fg.Files) {
$f.GrowthType = "KB";
$f.Growth = "102400"
$f.Alter();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment