2

Can explain why philosophically this doesn't work? Just as a learning example, I wanted to see the properties of the get-service cmdlet, without the events or methods.

PS C:\Users\Neal> get-service | get-member |  {$_.name -eq "Property"}

Result:

At line:1 char:29
+ get-service | get-member |  {$_.name -eq "Property"}
+                             ~~~~~~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
NealWalters
  • 17,197
  • 42
  • 141
  • 251

1 Answers1

5

{$_.name -eq "Property"} is just a scriptblock. If you want to use Where-Object to filter the results of get-member, you need to type Where-Object:

PS C:\Users\Neal> get-service | get-member | Where-Object {$_.name -eq "Property"}

or you can use where, which is an alias for Where-Object:

PS C:\Users\Neal> get-service | get-member | where {$_.name -eq "Property"}

There is even a special character ? which refers to Where-Object:

PS C:\Users\Neal> get-service | get-member | ? {$_.name -eq "Property"}

All three examples given above do the same thing. Choosing between them is simply a matter of style.

Community
  • 1
  • 1