How to count objects in PowerShell?

后端 未结 5 2167
星月不相逢
星月不相逢 2020-12-07 14:17

As I\'m reading in the PowerShell user guide, one of the core PowerShell concepts is that commands accept and return objects instead of text. So for example, runnin

5条回答
  •  轮回少年
    2020-12-07 15:01

    This will get you count:

    get-alias | measure
    

    You can work with the result as with object:

    $m = get-alias | measure
    $m.Count
    

    And if you would like to have aliases in some variable also, you can use Tee-Object:

    $m = get-alias | tee -Variable aliases | measure
    $m.Count
    $aliases
    

    Some more info on Measure-Object cmdlet is on Technet.

    Do not confuse it with Measure-Command cmdlet which is for time measuring. (again on Technet)

提交回复
热议问题