Public/Get-Diskspace.ps1

function Get-DiskSpace {
    <#
    .SYNOPSIS
        Returns disk space usage for local volumes.
 
    .DESCRIPTION
        Wraps Get-Volume to return drive letter, total size, free space,
        and percent free as a clean object, with an optional filter for
        drives below a given free-space threshold.
 
    .PARAMETER MinFreePercent
        Only return volumes whose free space percentage is at or below
        this value. Default is 100 (returns all volumes).
 
    .EXAMPLE
        Get-DiskSpace
 
        Returns all local volumes with size info.
 
    .EXAMPLE
        Get-DiskSpace -MinFreePercent 15
 
        Returns only volumes with 15% or less free space - useful for
        finding drives that are nearly full.
    #>

    [CmdletBinding()]
    param (
        [Parameter()]
        [ValidateRange(0, 100)]
        [double]$MinFreePercent = 100
    )

    Get-Volume | Where-Object { $_.DriveLetter } | ForEach-Object {
        $percentFree = if ($_.Size -gt 0) {
            [math]::Round(($_.SizeRemaining / $_.Size) * 100, 1)
        } else {
            0
        }

        if ($percentFree -le $MinFreePercent) {
            [PSCustomObject]@{
                DriveLetter   = $_.DriveLetter
                TotalSizeGB   = [math]::Round($_.Size / 1GB, 2)
                FreeSpaceGB   = [math]::Round($_.SizeRemaining / 1GB, 2)
                PercentFree   = $percentFree
                FileSystem    = $_.FileSystem
            }
        }
    }
}