I have been monitoring disk space on several servers for about 2 months now. The script runs every 15 minutes and sends me a list of drives that have less than X % of free space. Here’s the meat of the code (credit to Sean Duffy on Simple-Talk.com for the main logic of this):
$tableFragment = Get-WMIObject -ComputerName $computers -ErrorAction “Continue” -ErrorVariable errors 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]$thresholdspace} `
| ConvertTo-HTML -fragment
It then sends an email with an HTML table, using the tableFragment variable as the body. This all has worked swimmingly, except for one small hiccup. 2 times now, I have received an email, each time for a different server, that all of it’s disks are reading a size of 0GB. Then the next time the script runs 15 minutes later, everything is reported as normal. Has anyone seen this before? It is not an issue of the script not being able to connect to the server, because 1) that throws a different error, which I am catching, and 2) the script reads each drive and reports it with the correct drive name, but just reports it as having a size of 0. The script has ran about 5,000 times over the last 2 months, and something caused 2 of those times to not be able to correctly read drive sizes on 2 different servers. Any ideas?