powershell max/first/aggregate functions

前端 未结 3 1107
日久生厌
日久生厌 2021-01-17 07:24

First of all, i`m .NET developer and LOVE LINQ and extension methods in C#. But when i scripting i need something equivalent to Enumerable extension methods

Can anyb

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 08:06

    Use the Measure-Object command:

    C:\PS> 2,1,3 | Measure-Object -Maximum
    
    
    Count    : 3
    Average  :
    Sum      :
    Maximum  : 3
    Minimum  :
    Property :
    

    Or to get just the max:

    C:\PS> (2,1,3 | Measure -Max).Maximum
    

    There's also a Minimum, Average and Sum available as you can see from above. But you have to tell PowerShell to compute those with parameters to Measure-Object e.g. -Sum -Average etc.

提交回复
热议问题