Powershell - Displaying disk space informatione

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!

Hi, here’s how to display disk space information in Powershell

Get-CimInstance -Class Win32_logicaldisk | select-object -Property @{
Name = 'Drive'
Expression = { $_.DeviceID }
}, @{
Name = 'Total size (GB)'
Expression = { ('{0,18:N0}' -f ($_.Size / 1gb)) }
}, @{
Name = 'Free Space (GB)'
Expression = { ('{0,18:N0}' -f ($_.Freespace / 1gb)) }
}, @{
Name = 'Free (%)'
Expression = { '{0,7:P0}' -f (($_.Freespace / 1gb) / ($_.size / 1gb)) }
}

Or more cosmetically for demonstrations

# Color of values.
$colour = 'Yellow'
# Bar size (in number of characters)
$bar = 20
Get-CimInstance win32_logicalDisk |
ForEach-Object -process {
$utilise=($_.size - $_.freespace)/$_.size * $bar
$reste=$bar - $utilise
write-host 'Name: ' -NoNewline
write-host "$($_.deviceID) " -ForegroundColor Cyan -NoNewline
write-host "$("$([char]9604)" * $utilise)" -f red -NoNewline
write-host "$("$([char]9604)" * $reste)" -f green -NoNewline
write-host ' Size: ' -NoNewline
write-host "$("{0,10:N1}" -f ($_.size/1GB)) Go" -ForegroundColor $colour -NoNewline
write-host ' Free: ' -NoNewline
write-host "$("{0,10:N1}" -f ($_.freespace/1GB)) Go" -ForegroundColor $colour -NoNewline
write-host ' Used: ' -NoNewline
write-host "$("{0,10:N1}" -f (($_.size - $_.freespace)/1GB)) Go" -ForegroundColor $colour -NoNewline
write-host ' % free: ' -NoNewline
write-host "$("{0:P1}" -f (($_.freespace)/$_.size))" -ForegroundColor $colour }

Related links