The hard way.... sheesh 🙂
Pass in an SMO sql object and here you go! (doing the log files is that easy as well)
Function Get-DatabaseFilesBySpaceAvailable ([Microsoft.SqlServer.Management.Smo.Server] $SmoSqlServer
, [decimal] $sizeThreshold=0.85)
{
$sqlServer.Databases | Where-Object{$_.Status -eq "Normal"} `
| Select-Object FileGroups -ExpandProperty FileGroups `
| Select-Object Files -ExpandProperty Files `
| Where-Object {$_.MaxSize -gt -1} `
| Where-Object {$_.Size -gt ($_.MaxSize * $sizeThreshold)} `
| Select Name,UsedSpace,Size,MaxSize
}
Cheers
http://twitter.com/widba
http://widba.blogspot.com/