Monitor Disk Space with PowerShell for Efficient Management
Welcome to today's feature on enhancing IT operations through automation. We bring you a PowerShell script to monitor disk space usage on your servers, helping prevent downtime by proactively managing resources. Efficiently maintaining disk space is crucial to ensure your systems run smoothly without interruptions. This script pairs excellently with our ServerEngine software, which is designed to bolster your server automation strategies. By integrating ServerEngine with PowerShell scripts like this one, you can further streamline your server management tasks and focus on critical business functions. Dive into the script below and see how you can ensure optimal performance across your server environments:
# PowerShell script to monitor disk space and send alerts for low space
# Define threshold for low disk space in GB
$lowSpaceThreshold = 20
# Get all logical disks
$disks = Get-PSDrive -PSProvider FileSystem
# Function to check disk space
foreach ($disk in $disks) {
# Calculate free space in GB
$freeSpaceGB = [math]::Round($disk.Free / 1GB, 2)
if ($freeSpaceGB -lt $lowSpaceThreshold) {
$message = "Warning: Disk [$($disk.Name)] on server [$env:COMPUTERNAME] has low free space: $freeSpaceGB GB"
# Print alert message
Write-Host $message -ForegroundColor Red
# Add your custom notification action here, e.g., send an email or log the event
} else {
Write-Host "Disk [$($disk.Name)] has sufficient free space: $freeSpaceGB GB"
}
}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.