Reputation: 477
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.
Upvotes: 3
Views: 11985
Reputation: 26
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.
Upvotes: 1