Disk space of all volumes, with the free percentage
Win32_Volume describes every local volume, including those without a drive letter (recovery partition, volume mounted in a folder). Win32_LogicalDisk only sees lettered drives, but it also returns network drives.
Get-CimInstance -ClassName Win32_Volume -Filter 'DriveType = 3 AND Capacity > 0' |
Select-Object -Property @(
'DriveLetter'
'Label'
'FileSystem'
@{ Name = 'SizeGB'; Expression = { [math]::Round($_.Capacity / 1GB, 2) } }
@{ Name = 'FreeGB'; Expression = { [math]::Round($_.FreeSpace / 1GB, 2) } }
@{ Name = 'FreePercent'; Expression = { [math]::Round(100 * $_.FreeSpace / $_.Capacity, 1) } }
) |
Sort-Object -Property FreePercent
The WQL filter keeps local disks (DriveType = 3) and drops volumes without capacity. The sort puts the fullest volumes first.
Variant: only nearly full volumes
$thresholdPercent = 15
Get-CimInstance -ClassName Win32_Volume -Filter 'DriveType = 3 AND Capacity > 0' |
Where-Object -FilterScript { (100 * $_.FreeSpace / $_.Capacity) -lt $thresholdPercent } |
Select-Object -Property DriveLetter, Label, FreeSpace
Variant: several servers
With one session per server, the PSComputerName column identifies the source:
$cimSession = New-CimSession -ComputerName 'SERVER01', 'SERVER02'
try {
$cimParameters = @{
CimSession = $cimSession
ClassName = 'Win32_Volume'
Filter = 'DriveType = 3 AND Capacity > 0'
}
Get-CimInstance @cimParameters |
Select-Object -Property PSComputerName, DriveLetter, FreeSpace, Capacity
} finally {
Remove-CimSession -CimSession $cimSession
}