← script library

Streamline Disk Space Monitoring with PowerShell

Monitoring & HealthDecember 24, 2024

In this post, we will share a PowerShell script that helps you monitor disk space on your Windows machines efficiently. Keeping an eye on disk usage is crucial for maintaining optimal system performance and preventing unexpected downtime due to a lack of storage. This script checks the available space on local drives and alerts the admin if any drive falls below a specified threshold, ensuring proactive management of your system's resources. Here is the PowerShell script for monitoring disk space:

powershell
# Define the threshold for disk space (in GB)
$threshold = 10
# Get all local disk drives
$drives = Get-PSDrive -PSProvider FileSystem
# Check each drive's available space
foreach ($drive in $drives) {
    $availableSpaceGB = [math]::round($drive.Free / 1GB, 2)
    if ($availableSpaceGB -lt $threshold) {
        Write-Host "Warning: Drive $($drive.Name) has only $availableSpaceGB GB left." -ForegroundColor Red
    } else {
        Write-Host "Drive $($drive.Name) is healthy with $availableSpaceGB GB free."
    }
}

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.