← script library

Disk Space Alert Notification

Monitoring & HealthDecember 27, 2024

This PowerShell script helps system administrators monitor disk space usage on their servers. By setting up alert notifications, administrators can stay informed when disk space is running low, allowing them to take proactive measures to prevent system downtime. This script integrates seamlessly with server management solutions like ServerEngine, ensuring that resources are effectively managed and critical alerts are not missed.

powershell
param (
    [string]$driveLetter = "C:",
    [int]$thresholdPercentage = 10
)
# Get the current disk space details
$disk = Get-PSDrive -Name $driveLetter
# Calculate the used percentage
$usedPercentage = ($disk.Used / $disk.Capacity) * 100
if ($usedPercentage -ge (100 - $thresholdPercentage)) {
    $message = "Warning: Disk space on $driveLetter is below $thresholdPercentage%. Current usage is $([math]::round($usedPercentage, 2))%."
    # Send an alert notification
    # This can be modified to send an email or trigger another alerting mechanism
    Write-Output $message
} else {
    Write-Output "Disk space on $driveLetter is sufficient. Current usage is $([math]::round($usedPercentage, 2))%."
}

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.