Tested script

Report free space on every drive (PowerShell)

Shows size, free space and percent free for each fixed drive, and flags any below a threshold. Use it for a quick health check or as a scheduled task that exits with code 2 when space is low.

Tested

The script

<#
.SYNOPSIS
    Reports free space on each fixed drive or volume.
.DESCRIPTION
    Uses the .NET DriveInfo class, so it works on Windows, Linux and macOS
    without extra modules. Drives below -WarnBelowPercent are flagged, and the
    script exits with code 2 so a scheduler or monitoring tool can react.
    Read-only.
.PARAMETER WarnBelowPercent
    Flag drives with less free space than this percentage. Defaults to 15.
.EXAMPLE
    ./Get-DriveFreeSpace.ps1
.EXAMPLE
    ./Get-DriveFreeSpace.ps1 -WarnBelowPercent 25
#>
[CmdletBinding()]
param(
    [ValidateRange(0, 100)]
    [int]$WarnBelowPercent = 15
)

$drives = [System.IO.DriveInfo]::GetDrives() |
    Where-Object { $_.IsReady -and $_.DriveType -eq 'Fixed' -and $_.TotalSize -gt 0 }

if (-not $drives) {
    Write-Error 'No fixed drives found.'
    exit 1
}

$report = foreach ($drive in $drives) {
    $freePercent = [math]::Round(($drive.AvailableFreeSpace / $drive.TotalSize) * 100, 1)
    [PSCustomObject]@{
        Drive       = $drive.Name
        Label       = $drive.VolumeLabel
        SizeGB      = [math]::Round($drive.TotalSize / 1GB, 1)
        FreeGB      = [math]::Round($drive.AvailableFreeSpace / 1GB, 1)
        FreePercent = $freePercent
        Status      = if ($freePercent -lt $WarnBelowPercent) { 'LOW' } else { 'OK' }
    }
}

$report | Sort-Object -Property FreePercent | Format-Table -AutoSize

$low = @($report | Where-Object { $_.Status -eq 'LOW' })
if ($low.Count -gt 0) {
    Write-Warning "$($low.Count) drive(s) below $WarnBelowPercent% free."
    exit 2
}
exit 0

Run it

./Get-DriveFreeSpace.ps1
./Get-DriveFreeSpace.ps1 -WarnBelowPercent 25

How it works

Parameter

-WarnBelowPercent sets the level that counts as low. It defaults to 15 and must be between 0 and 100.

Find the drives

[System.IO.DriveInfo]::GetDrives() is a .NET call that works on every platform PowerShell runs on. Where-Object keeps only drives that are ready, fixed (not DVD or network) and have a size, using -and to combine the tests.

Build the report

A foreach loop works out the percent free for each drive and builds a [PSCustomObject] with tidy columns. An if inside the object sets Status to LOW or OK by comparing with -lt.

Show it and set the exit code

The report is sorted with the emptiest drive first. If any drive is low, the script prints a warning and exits with code 2. Exit code 0 means everything is fine and 1 means no drives were found. A monitoring tool or scheduled task can act on those codes without reading the text.

On Linux

Each mount point shows up as its own drive, so bind mounts of the same disk appear more than once with identical numbers. The label column just repeats the mount point.