Ansgar Wichers provided a key pointer in a commentary on Martin Brandle's answer:
The canonical way would be ForEach-Object . This can be written quite briefly using the alias % :
... | % { $_.GetSomething() }
In PowerShell version 3 or higher, you can make the call even more concise with the operation operator , which eliminates the need to enclose the call in {... } , explicitly reference $_ and use parentheses ( (...) ):
... | % GetSomething
Note that if a method accepts arguments, they must be represented as an array ( , -separated), but without enclosing them in (...) , since the arguments are syntactically passed in argument mode , which also simplifies quoting a simple string; optional values ββ- see examples below.
Examples :
Method call without arguments:
A method call with one argument:
# Perform the equivalent of (Get-Date).ToString('u'); ie,
Calling a method with multiple arguments:
# Perform the equivalent of 'foo'.Replace('f', 'F'); ie,
source share