【问题标题】:What measure means in Powershell?Powershell中的度量是什么意思?
【发布时间】:2017-10-10 23:05:52
【问题描述】:

在这里看到Get minimum value in an array and then get index

$myArray = [int[]]5,66,4,33,2,9,9,12
$minvalue=[int]($myArray | measure -Minimum).Minimum
$myArray.IndexOf($minvalue)

但无法在 Google 上找到它的意思,因为我只能找到 Measure-Object。

【问题讨论】:

  • 快速提示:Get-Command Measure

标签: powershell


【解决方案1】:

找出命令做什么(或更严格地说,它是什么)的最简单方法是使用Get-Command。对于您的情况,它告诉您 Measure 是 - 就像其他回答者已经告诉的那样 - Measure-Object 的别名:

PS> Get-Command measure

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           measure -> Measure-Object

真正的作用可以通过Get-Help 找到 - 在你的情况下 - 会导致:

SYNOPSIS
    Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files of text.

注意:Get-Commandgcm 的别名,Get-Helphelp 的别名。请记住,虽然别名在交互式 shell 中可能对您有所帮助,但在脚本中应避免使用。

【讨论】:

    【解决方案2】:

    MeasureMeasure-Object 的标准 PowerShell 别名。使用 MeasureMeasure-Object 做同样的事情。

    您也可以通过运行以下命令使用 PowerShell 验证这一点:

    Get-Alias measure
    

    【讨论】:

    • 我会在布丁中添加这个作为证据get-alias measure
    • 虽然 PowerShell 不区分大小写,但我更喜欢使用大小写。最后但并非最不重要的一点是,它帮助 StackOverflow 语法高亮显示它。
    【解决方案3】:

    PowerShell 中的另一个常见任务是测量一组对象 基于一些数字属性。用于此任务的 cmdlet 是 Measure-Object,别名为measure。你需要做的就是 指定属性名称和要执行的测量类型。这 cmdlet 具有用于添加值 (-Sum) 的参数,计算 平均值(-Average),并找到最小值(-Minimum)和 最大值(-Maximum)。

    作者 Jeffery Hicks 来自文章:http://m.windowsitpro.com/powershell/powershell-basics-sorting-measuring-objects

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多