I have a bigger script that sends emails when disk of various computer is under 20%. Now I have one computer that is under 20%, but has 40 GB, so I want to add a second filter to only send the email when the FreeSpace < 10 GB.
I can't get the additional filter to work, even though it seems like what I'm doing is logical.
[decimal]$thresholdPercentFree = 20
[decimal]$thresholdFreespaceGB = 10
Write-Host "TEST1"
Get-WMIObject -ComputerName $computers Win32_LogicalDisk `
| select __SERVER, DriveType, VolumeName, Name, @{n='Size (Gb)' ;e={"{0:n2}" -f ($_.size/1gb)}},@{n='FreeSpace (Gb)';e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, @{n='PercentFree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} `
| Where-Object {$_.DriveType -eq 3 -and [decimal]$_.PercentFree -lt [decimal]$thresholdPercentFree }
Write-Host "TEST2"
Get-WMIObject -ComputerName $computers Win32_LogicalDisk `
| select __SERVER, DriveType, VolumeName, Name, @{n='Size (Gb)' ;e={"{0:n2}" -f ($_.size/1gb)}},@{n='FreeSpace (Gb)';e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, @{n='PercentFree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} `
| Where-Object {$_.DriveType -eq 3 -and [decimal]$_.PercentFree -lt [decimal]$thresholdPercentFree -and [decimal]($_.FreeSpace/1gb) -lt $thresholdFreespaceGB}
Output: The desire is that Test2 will not show any servers because the FreeSpace > 10.
TEST1
__SERVER : MyServerName
DriveType : 3
VolumeName :
Name : C:
Size (Gb) : 249.66
FreeSpace (Gb) : 46.18
PercentFree : 18.50
TEST2
__SERVER : MyServerName
DriveType : 3
VolumeName :
Name : C:
Size (Gb) : 249.66
FreeSpace (Gb) : 46.18
PercentFree : 18.50