Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.