What is the Linq.First equivalent in PowerShell?

后端 未结 4 1008
孤城傲影
孤城傲影 2021-02-01 12:44

The snippet below detects from a list of files which of them is a Directory on Ftp

as C# it will be like below

var files = new List(){\"App         


        
4条回答
  •  悲哀的现实
    2021-02-01 13:35

    as Robert Groves said, Select-Object -First Occurence do the tricks, you can also use -Last Occurence.

    by the way, like any other static .Net method you can use linq in powershell.

    [Linq.Enumerable]::First($list)
    
    [Linq.Enumerable]::Distinct($list)
    
    [Linq.Enumerable]::Where($list, [Func[int,bool]]{ param($item) $item -gt 1 })
    

提交回复
热议问题