How does -InputObject parameter of the Sort-Object cmdlet work?

后端 未结 2 497
南方客
南方客 2021-01-13 01:01

PowerShell 4.0

I read about Sort-Object cmdlet here (TechNet page). I don\'t understand how to use -InputObject parameter. That page hasn\'

2条回答
  •  情歌与酒
    2021-01-13 01:43

    The process block of a function automatically deals with a collection over a pipe, but not if it's passed as a command line argument. Some cmdlets put in an extra foreach loop to process -inputobject collections or lists, but most don't.

    However, any parameter that can take input from a pipe, can also take a script block from the command line. So that may come in handy some time. You'll see examples like this in the help.

    PS C:\> echo a,b,c,d | sort -InputObject { $_.ToUpper() } -Descending
    D
    C
    B
    A
    

提交回复
热议问题