Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 549 Bytes

Advanced-Console-Tricks.md

File metadata and controls

31 lines (20 loc) · 549 Bytes

Advanced Console Tricks

Foreach-Object Advanced Syntax

(Get-Process).Id

can expressed by a pipeline command

Get-Process |% Id

which translates to

Get-Process | Foreach-Object { $_.Id }

This short form of writing Foreach-Object is actually also available for method calls:

Get-Process |% WaitForExit 55

Advantages

you dont have to go to the beginning of the line, and put an opening brace there.
An alternative solution to this is Select-Object -ExpandProperty, but its much longer.