I'm trying to get the disk usage from all disks and then send out an email if the disk usage is more than 80% for any of the disks. Using the existing articles, I came up with the below but not able to filter out disks with more than 80% usage. Can some kind soul guide me? TIA
$size = @{label="Size(GB)";expression={[int]($_.Size/1GB)}}
$freeSpace = @{label="FreeSpace(GB)";expression={[int]($_.FreeSpace/1GB)}}
$freeSpacePercent = @{label="FreeSpace(%)";expression={[int]($_.FreeSpace/$_.Size * 100)}}
Get-CimInstance -ClassName Win32_LogicalDisk |
Select-Object -Property DeviceID,VolumeName,$size,$freeSpace,$freeSpacePercent
Just add a
Where-Object{}
, something like:Notice it's less than 20%. Also notice the quotes, because you used special characters in the property name.
Also, you are casting to an
[Int]
which is going to bankers round very roughly top the whole number. That might be intentional, but whe I do this sort of thing I like to use the `[Math]::Round() function. You can change your expressions to get that: