WIDBA - The busiest DBA in Wisconsin, its all I do and I do it well

Friday, May 20, 2011

Powershell Monitoring drive space - improvements

 Here is an improvement on finding drives that are running low on space.  It returns the drive, size, free space and the amount of MB of space you want minimally (based on the $thresholdMultiplier).

## Return any physical drive on server(note $filter) that has less than 20% free space ($thresholdMultiplier)
function Get-DriveSpace
    param( [Parameter(Mandatory=$true)]$computer , [int]$thresholdMultiplier=.20 )
    [string]$filter = "DriveType = '3'"

        Get-WmiObject -class win32_logicaldisk -filter $filter -comp $computer |
            Select-Object Name,@{label="SizeMB";Expression={[Math]::Truncate($_.Size / 1MB)}},
            @{label="FreeMB";Expression={[Math]::Truncate($_.FreeSpace / 1MB)}},
            @{label="WarningMB";Expression={[Math]::Truncate(($_.Size * $thresholdMultiplier) /1MB)}}|
            Where-Object{$_.FreeMB -le $_.WarningMB}
    } catch {
        Write-Verbose "Error $Error in getting disk space for $computer"

No comments:

Post a Comment