PowerShell: disk space report for every fixed drive
The script
Query Win32_LogicalDisk with DriveType=3 (fixed disks) and compute free space and percentage. The variation exits non-zero when any drive drops under 10% free, which turns the script into a monitor anything can alert on.
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
Select-Object DeviceID,
@{n='SizeGB'; e={[math]::Round($_.Size/1GB, 1)}},
@{n='FreeGB'; e={[math]::Round($_.FreeSpace/1GB, 1)}},
@{n='FreePct'; e={[math]::Round(100 * $_.FreeSpace/$_.Size)}} |
Format-Table -AutoSize
Notes before you run it
- Windows itself starts misbehaving below roughly 10% free on the system drive: updates fail, profiles will not load, VSS snapshots die.
- The usual culprits, in order: the
SoftwareDistributioncache, old user profiles, shadow copies (vssadmin list shadowstorage), and log folders someone meant to rotate.
Alert version: exit 1 when any drive is under 10% free
$low = Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
Where-Object { $_.Size -gt 0 -and ($_.FreeSpace / $_.Size) -lt 0.10 }
if ($low) {
$low | ForEach-Object { "{0} has {1:n1} GB free" -f $_.DeviceID, ($_.FreeSpace/1GB) }
exit 1
}
"All drives above 10% free."
Run it on every machine, not one at a time.
Save any of these as a command in Moorfox and run it on a machine in one click, output and exit code captured, with no PSRemoting or WinRM setup. The agent runs it locally and reports back, even over the internet.