Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell-lt和-gt给出与预期结果相反的结果_Powershell_Get Wmiobject - Fatal编程技术网

Powershell-lt和-gt给出与预期结果相反的结果

Powershell-lt和-gt给出与预期结果相反的结果,powershell,get-wmiobject,Powershell,Get Wmiobject,在下面的代码中,如果我添加一个where对象,-lt&-gt,则给出的结果与预期结果相反 我相信原因是我很愚蠢,但我到底是怎么搞砸的 这一部分给出了预期的结果,在我的例子中,单个驱动器有39.8%的空闲时间 Get-WmiObject -Namespace root\cimv2 -Class win32_logicaldisk | where-object -Property drivetype -eq 3 | format-table deviceid, @{n='GB Capacity';

在下面的代码中,如果我添加一个where对象,-lt&-gt,则给出的结果与预期结果相反

我相信原因是我很愚蠢,但我到底是怎么搞砸的

这一部分给出了预期的结果,在我的例子中,单个驱动器有39.8%的空闲时间

Get-WmiObject -Namespace root\cimv2 -Class win32_logicaldisk | where-object -Property drivetype -eq 3 | 
format-table deviceid,
@{n='GB Capacity';e={$_.size/1gb}},
@{n='GB Free';e={$_.freespace/1gb}},
@{n='%Free';e={($_.freespace/$_.size)*100}}
但是加上这个

| where {$_.'%Free' -gt 10}
结果没有输出。其实

| where {$_.'%Free' -gt 0}
没有结果。相反,我必须使用

| where {$_.'%Free' -lt 0}

Powershell认为%Free是个负数,我猜

问题在于,您正在将
表格格式
传送到任何内容。除了输出到屏幕外,您不应该使用它。使用
Format Table
将所有内容作为Format对象输出,而不是管道中的任何内容。而是使用
Select Object
来获取所需内容

Get-WmiObject -Namespace root\cimv2 -Class win32_logicaldisk | where-object -Property drivetype -eq 3 | 
Select-Object deviceid,
@{n='GB Capacity';e={$_.size/1gb}},
@{n='GB Free';e={$_.freespace/1gb}},
@{n='%Free';e={($_.freespace/$_.size)*100}}

啊!我甚至没有意识到我做了那件事。正是我需要的,谢谢!