In PowerShell, what does the symbol % represent in the pipeline?

Study for the SANS560 GIAC Penetration Tester (GPEN) Test. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Multiple Choice

In PowerShell, what does the symbol % represent in the pipeline?

Explanation:
In PowerShell, the % symbol is the alias for ForEach-Object. It processes each item flowing through the pipeline by executing a script block for that item, effectively transforming or acting on every object as it passes through. Inside the script block, the current item is referred to as $_ (or $PSItem). For example, Get-Service | % { $_.Status } applies the block to each service and outputs its status, or Get-ChildItem | % { $_.Name.ToUpper() } outputs the names in uppercase. This is different from filtering, which uses a condition to pass along only some items; the % alias is about per-item processing and transformation.

In PowerShell, the % symbol is the alias for ForEach-Object. It processes each item flowing through the pipeline by executing a script block for that item, effectively transforming or acting on every object as it passes through. Inside the script block, the current item is referred to as $_ (or $PSItem). For example, Get-Service | % { $.Status } applies the block to each service and outputs its status, or Get-ChildItem | % { $.Name.ToUpper() } outputs the names in uppercase. This is different from filtering, which uses a condition to pass along only some items; the % alias is about per-item processing and transformation.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy