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.
More in Monitoring & Health
Disk Space Cleanup and Report Script
2025-01-14User Account Status Reporting Script
2025-01-13Automated Disk Space Monitoring Script
2025-01-13Monitor System Performance with PowerShell
2025-01-12Automating System Health Check with PowerShell
2025-01-05Automate System Performance Monitoring with PowerShell
2024-12-30Ready when you are.
Try ServerEngine free for 7 days.