Check Disk Space

Monitors disk space usage across all drives and alerts if usage exceeds threshold.

beginnerSystem Administrationdiskstoragemonitoringalerts
check-disk-space.ps1
1param(
2 [int]$ThresholdPercent = 80
3)
4
5Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | ForEach-Object {
6 $usedPercent = [math]::Round((($_.Size - $_.FreeSpace) / $_.Size) * 100, 2)
7 $status = if ($usedPercent -ge $ThresholdPercent) { "WARNING" } else { "OK" }
8
9 [PSCustomObject]@{
10 Drive = $_.DeviceID
11 SizeGB = [math]::Round($_.Size / 1GB, 2)
12 FreeGB = [math]::Round($_.FreeSpace / 1GB, 2)
13 UsedPercent = $usedPercent
14 Status = $status
15 }
16}
Quick Actions
Parameters
  • $ThresholdPercent(number)

    Alert threshold percentage

    Default: 80

Use Cases
  • Monitor disk space on servers or workstations to prevent storage issues before they impact operations.
Details
CategorySystem Administration
Complexitybeginner
Added3/13/2026
Check Disk Space - PowerShell Hub