Disk Space Monitoring and Notification

This script checks available disk space and sends a notification if space is below a certain threshold.


# Define threshold in GB
$thresholdGB = 10
$volumes = Get-PSDrive -PSProvider FileSystem

foreach ($volume in $volumes) {
    if ($volume.Used / 1GB -gt ($volume.Used + $volume.FreeSpace - $thresholdGB) / 1GB) {
        Write-Output "Warning: Drive $($volume.Name) has less than $thresholdGB GB free space."
        # Optional: Send-MailMessage can be used here for email alerts
    } else {
        Write-Output "Drive $($volume.Name) has sufficient space."
    }
}

• Explanation: This script loops through each drive, checking if available space is below a defined threshold. If so, it displays a warning and can be customized to send an email alert.

Last updated