Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting disk usage using powershell command

Tags:

powershell

I am trying to get the disk usage using the below command.

C:\Users\arjun> (Get-PSDrive $drivename)

WARNING: column "CurrentLocation" does not fit into the display and was removed
.

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
A                                      FileSystem    A:\
Alias                                  Alias
C                  45.29          4.70 FileSystem    C:\
cert                                   Certificate   \
D                  36.86         13.14 FileSystem    D:\
E                 230.36         19.64 FileSystem    E:\
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
T                  10.84         39.16 FileSystem    T:\
Variable                               Variable
WSMan                                  WSMan
Y                                      FileSystem    Y:\

I am getting the above result, however when I try to fetch one column its failing.

(Get-PSDrive $drivename).Used..

Note that is is legacy windows system. Is there any alternative for this. I tried the same command on non-legacy systems and its works fine.

like image 343
Pradeep Shanbhag Avatar asked Dec 17 '25 13:12

Pradeep Shanbhag


1 Answers

Hello I see what you are doing there might seem rather logical but powershell doesn't know which drive you are defining. So what you should be doing is the following.

$drivename.PSDrive.Used

This way it will exactly know which drive is meant. As Output you will get Byte so you should propably save it into an Variable and then format it.

What you should also be aware of is saving the variable $drivename correctly. That mean that you should save it alike this.

$drivename = Get-Item "C:\Users\arjun"

So it could be that you perhaps forgot to save the object instead of only the path name, or maybe you forgot the quotemarks. Please be sure to check this and mark this answered if it helped you out.

like image 147
C3R3S1A Avatar answered Dec 20 '25 10:12

C3R3S1A



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!