← script library

Automated Disk Space Monitoring Script

Monitoring & HealthJanuary 13, 2025

This PowerShell script helps administrators monitor disk space usage on specified drives. By automating this task, the script ensures timely warnings about low disk space, helping to maintain system performance and prevent potential issues.

powershell
$drives = @('C:', 'D:', 'E:')
$threshold = 10  # Threshold in GB

foreach ($drive in $drives) {
    $diskSpace = Get-PSDrive -Name $drive
    $availableSpaceGB = [math]::round($diskSpace.Free / 1GB, 2)
    if ($availableSpaceGB -le $threshold) {
        Write-Host "Warning: Drive $drive has only $availableSpaceGB GB left."
    } else {
        Write-Host "Drive $drive has $availableSpaceGB GB available."
    }
}

$logFilePath = "C:\DiskSpaceLog.txt"
$currentDateTime = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
foreach ($drive in $drives) {
    $diskSpace = Get-PSDrive -Name $drive
    $availableSpaceGB = [math]::round($diskSpace.Free / 1GB, 2)
    $logMessage = "$currentDateTime - Drive $drive: $availableSpaceGB GB available"
    Add-Content -Path $logFilePath -Value $logMessage
}

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.