In this post, we will provide a PowerShell script that allows you to monitor disk space usage across your system. Keeping track of available disk space is crucial for preventing unexpected issues due to insufficient storage. This script checks the current usage of all drives and presents a concise report, allowing administrators to identify drives that may require attention. Here is the PowerShell script for monitoring disk space usage:
powershell
# Get the disk space information for all drives
$drives = Get-PSDrive -PSProvider FileSystem
# Prepare the report
$diskSpaceReport = @()
foreach ($drive in $drives) {
$diskSpaceReport += [PSCustomObject]@{
Drive = $drive.Name
UsedSpaceGB = [math]::round($drive.Used / 1GB, 2)
FreeSpaceGB = [math]::round($drive.Free / 1GB, 2)
TotalSpaceGB = [math]::round($drive.Used / 1GB + $drive.Free / 1GB, 2)
PercentFree = [math]::round(($drive.Free / ($drive.Used + $drive.Free)) * 100, 2)
}
}
# Output the disk space report
$diskSpaceReport | Format-Table -AutoSize
Write-Host "Disk space monitoring completed successfully."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.