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.

  • Ian,

    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.

    ...Yes that was correct, In future I'll add such code just for completeness. Thank you for your reply, as it happens you were very close but it did not sum. But your answer still helped me out. I think I was a bit burned out on Friday not to think if this myself, but your code did indeed point me in the right direction. I ended up with...

    $UserDBs = $Server.Databases | Where-Object {$_.IsSystemObject -eq $False}

    $SumOfMaxSize = ($UserDBs.filegroups.files | Measure-Object -Sum Maxsize).sum

    ...on Friday I had tried incorporating IsSystemObject, but could not work out how to get it to work when piping, I see where I want wrong not. So this gets me what I need, and much better than before.

    Jeff & Gaz, yes I know what you mean, I suppose I could have invoked SQL and ran the command submitted, I suppose I've become a bit to determined to do the whole thing in Powershell, but as it is part of automation I kind of prefer it.

    Thank you all for your replies, when I have finished I'll come back and talk about what I ended up automating.

    Regards,

    D.