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 = 20Get-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
Powershell - Testing network connectivity and port accessibility
Testing network connectivity and port accessibility with PowershellPowershell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)Powershell - Testing name resolution (equivalent to nslookup)
Powershell commands to test name resolution (equivalent to nslookup)Powershell - View and manage DNS configuration of network interfaces
Powershell commands to display and manage DNS configuration of network interfacesPowershell - Managing IP configuration of network interfaces
Powershell commands to view and modify the IP configuration of network interfacesPowershell - Managing the status and configuration of network interfaces
Powershell commands to view and modify the status and configuration of network interfaces (disable IPv6, enable/disable an interface)
Follow me on
Support me
Last content
Powershell - Testing network connectivity and port accessibility
Powershell - Display network connections (equivalent to netstat)
Powershell - Testing name resolution (equivalent to nslookup)
Powershell - View and manage DNS configuration of network interfaces
Powershell - Managing IP configuration of network interfaces
Powershell - Managing the status and configuration of network interfaces
Powershell and the Left Hand Side
Powershell - Managing disks, partitions and volumes