Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Disk Size and FreeSpace in GB

Tags:

powershell

Is there one line of code that will display free-size and disk-space of your logical disk in gb instead of mb? I tried doing some research but I couldn't find one liner, I did give this an attempt which was to divide it by 1GB, but that didn't work, how can I accomplish this?

gwmi win32_logicaldisk | Format-Table DeviceId, MediaType,Size,FreeSpace /1GB
like image 611
Katz Avatar asked May 11 '16 06:05

Katz


People also ask

How do I check how much disk space I have?

To check the total disk space left on your Windows 10 device, select File Explorer from the taskbar, and then select This PC on the left. The available space on your drive will appear under Devices and drives.

How do I find the size of my hard drive in Linux?

Linux command to check disk space using:df command – Shows the amount of disk space used and available on Linux file systems. du command – Display the amount of disk space used by the specified files and for each subdirectory.


1 Answers

Try calculated properties. I would also add [math]::Round() to shorten the values:

gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}

n stands for name and e for expression. You could use the full names too, but it's a waste of space if you're writing multiple calculated Properties.

like image 62
Frode F. Avatar answered Sep 27 '22 19:09

Frode F.