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
----           ---------     --------- --------      ----
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"

所以可能是您忘记了保存对象而不仅仅是路径名,或者您可能忘记了引号。如果对您有帮助,请务必检查并标记为已回答。

关于powershell - 使用 powershell 命令获取磁盘使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48761761/

相关文章:

regex - 如何使用Regex通过PowerShell从专有名称中仅提取CN

powershell - 有没有理由明确导入模块?

azure - 创建自签名证书并将其上传到 Azure 应用服务的最简单方法

powershell - 无法在 Core i7 上运行 Powershell 64

powershell - 如果文件名包含空格,则嵌入式PowerShell命令将不起作用

powershell - Get-ADUser -Filter {name -like "sakthi*"} -属性名称 |选择名称

Powershell 按行数分解 CSV

.net - 如何从 PowerShell 访问 Web 服务?

powershell - 当我想重命名powerShell中for循环中生成的文件时出错

python - 使用 Python 的 PowerShell 中的 Unicode? Windows 中的替代 shell?