使用powershell命令获取磁盘使用率

使用powershell命令获取磁盘使用率,powershell,Powershell,我正在尝试使用下面的命令获取磁盘使用情况 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 ---- --------- --------- ----

我正在尝试使用下面的命令获取磁盘使用情况

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:\
我得到了上面的结果,但是当我尝试获取一列时,它失败了

(Get-PSDrive $drivename).Used..

请注意,这是旧版windows系统。有没有别的办法。我在非旧式系统上尝试了相同的命令,效果很好。

您好,我知道您在那里做的事情似乎很合乎逻辑,但powershell不知道您定义的是哪个驱动器。所以你应该做以下几点

$drivename.PSDrive.Used
通过这种方式,它将确切地知道是哪个驱动器。作为输出,您将获得字节,所以您应该将其保存到变量中,然后对其进行格式化

您还应该注意的是正确保存变量$drivename。这意味着你应该像这样保存它

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

因此,可能是您忘记了保存对象而不仅仅是路径名,或者您忘记了引号。请务必勾选此项,并标记此项已回答,如果它有助于您解决问题。

您遇到了什么错误?这对我来说没有问题:
$drivename=“C”,“C”;(Get-PSDrive$drivename)。已使用
请阅读有关询问的帮助并相应地编辑您的帖子。我使用了下面的命令$drivenames=(Get-PSDrive-PSProvider FileSystem)。Name$使用=0$用法=0$totaldisksize=0;foreach($drivenames中的drivename){$usedspace=(Get-PSDrive$drivename).Used;$freespace=(Get-PSDrive$drivename).Free;if($usedspace-ne 0){$total=$freespace+$usedspace;$totaldisksize=$totaldisksize+([Math]::Round($freespace+$usedspace)/1GB,2))};写入主机$totaldisksize它不工作@PradeepShanbhag我不明白你为什么要使用这么复杂的代码。代码中有一些语法错误,比如在编写“$totaldisksize=$totaldisksize”的部分。必须是“$totaldisksize=$total”。