Monitor Disk Space Usage with PowerShell

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:

# 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."