Home Forums Programming Powershell Got what I need, but perhaps a more elegant solution is out there. Looping through SQL filegroups to get Maxsize. RE: Got what I need, but perhaps a more elegant solution is out there. Looping through SQL filegroups to get Maxsize.

  • I can't really work out how your code produces anything, but I'm not a Powershell expert by any means.

    I assume your $server object is an SMO server object that you have already created.

    If so, this ($Server.Databases.filegroups.files) would return nothing, as Filegroups is a property of an individual database, not the Databases collection.

    Try something like this:

    foreach ($db in $Server.databases | where-object {$_.IsSystemObject -eq $False})

    {

    foreach ($fg in $db.Filegroups)

    {

    $fg.files | measure-object maxsize -sum

    }

    }

    This isn't a full solution, it's just something to (hopefully) point you in the right direction, and there may be the odd syntax error, as I'm posting this from a device without access to Powershell.

    Even if it does work, there are flaws because an unlimited max size will just return -1, which will completely skew you sums.