小编Sti*_*sfa的帖子

如何使用PowerShell的"Measure-Object"cmdlet的"-Property"参数?

为什么

$a = GPS AcroRd32 | Measure
$a.Count
Run Code Online (Sandbox Code Playgroud)

工作,什么时候

GPS AcroRd32 | Measure -Property Count
Run Code Online (Sandbox Code Playgroud)

不?

第一个示例返回一个值2,这是我想要的一个整数.

第二个例子返回:

Measure-Object : Property "Count" cannot be found in any object(s) input.
At line:1 char:23
+ GPS AcroRd32 | Measure <<<<  -Property Count
    + CategoryInfo          : InvalidArgument: (:) [Measure-Object], PSArgumentException
    + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
Run Code Online (Sandbox Code Playgroud)



这个Scripting Guy条目是我学习如何在第一个代码示例中使用"Count"属性的地方.

第二个代码示例真的令人困惑.在此脚本中心参考中,以下语句有效:

Import-Csv c:\scripts\test.txt | Measure-Object score -ave -max -min
Run Code Online (Sandbox Code Playgroud)

它仍然有效,即使它重写如此:

Import-Csv c:\scripts\test.txt | Measure-Object -ave -max -min -property score
Run Code Online (Sandbox Code Playgroud)

在我考虑Measure-Object帮助页面之前,接受这个问题没有太多问题.状态的参数定义 …

syntax powershell powershell-2.0

6
推荐指数
3
解决办法
1万
查看次数

如何使用Get-Process中的Count属性返回漂亮的零值?

比较下面的三个脚本:

样品1

$a = GPS | Where {$_.ProcessName -Match 'AcroRd32'}
$a
$a.Count

If ($a.Count -Eq 0)
{
    Echo "Adobe Reader is Off"
}
Else
{
    Echo "Adobe Reader is On"
}

# If Adobe Reader is not running, how come 0 (zero) is not returned?
# This is prettier, should I use it?  Or does it slow down performance?
Run Code Online (Sandbox Code Playgroud)



样本2

$a = GPS AcroRd32
$a
$a.Count

If ($a.Count -Eq 0)
{
    Echo "Adobe Reader is Off"
}
Else
{
    Echo …
Run Code Online (Sandbox Code Playgroud)

powershell stderr powershell-2.0

5
推荐指数
1
解决办法
5652
查看次数

标签 统计

powershell ×2

powershell-2.0 ×2

stderr ×1

syntax ×1