Streamline Disk Space Monitoring with PowerShell

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:

# 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."
    }
}