Bird
Raised Fist0
PowerShellscripting~20 mins

Pipeline concept (|) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PowerShell Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell pipeline?
Consider the following PowerShell command pipeline. What will it output?
PowerShell
1..5 | Where-Object { $_ % 2 -eq 0 } | ForEach-Object { $_ * 10 }
A20`n40
B2`n4`n6`n8`n10
C10`n20
D1`n3`n5
Attempts:
2 left
💡 Hint
Think about filtering even numbers first, then multiplying each by 10.
💻 Command Output
intermediate
2:00remaining
What does this pipeline output?
What is the output of this PowerShell command?
PowerShell
'apple','banana','cherry' | Where-Object { $_.Length -gt 5 } | Sort-Object
Acherry`nbanana
Bbanana`ncherry
Capple`nbanana`ncherry
Dapple
Attempts:
2 left
💡 Hint
Filter words longer than 5 letters, then sort alphabetically.
🔧 Debug
advanced
2:00remaining
Why does this pipeline cause an error?
This PowerShell pipeline throws an error. What is the cause?
PowerShell
1..3 | ForEach-Object { $_ / 0 } | Where-Object { $_ -gt 1 }
ADivision by zero error in ForEach-Object block
BWhere-Object cannot process pipeline input
CSyntax error due to missing parentheses
DNo error; outputs 1, 2, 3
Attempts:
2 left
💡 Hint
Check the operation inside ForEach-Object carefully.
🚀 Application
advanced
2:00remaining
Which pipeline command lists files larger than 1MB and sorts by size?
You want to list files in the current folder larger than 1MB, sorted from largest to smallest. Which pipeline command does this?
AGet-ChildItem | Sort-Object Length -Descending | Where-Object { $_.Length -gt 1MB }
BGet-ChildItem | Sort-Object Length | Where-Object { $_.Length -lt 1MB }
CGet-ChildItem | Where-Object { $_.Length -lt 1MB } | Sort-Object Length
DGet-ChildItem | Where-Object { $_.Length -gt 1MB } | Sort-Object Length -Descending
Attempts:
2 left
💡 Hint
Filter first, then sort descending by size.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using pipelines in PowerShell scripting?
Why do PowerShell users prefer pipelines (|) when writing scripts?
AThey convert all output to plain text for easier reading
BThey automatically parallelize commands to run on multiple CPU cores
CThey allow chaining commands so output of one is input to next, enabling efficient data processing
DThey prevent any errors from stopping the script execution
Attempts:
2 left
💡 Hint
Think about how data flows between commands.

Practice

(1/5)
1. What does the pipeline operator | do in PowerShell?
easy
A. It runs two commands in parallel.
B. It comments out the rest of the line.
C. It creates a new variable.
D. It passes the output of one command as input to the next command.

Solution

  1. Step 1: Understand the pipeline operator

    The pipeline | connects commands so the output of the first command flows as input to the next.
  2. Step 2: Identify the correct description

    Only It passes the output of one command as input to the next command. correctly describes this behavior; others describe unrelated actions.
  3. Final Answer:

    It passes the output of one command as input to the next command. -> Option D
  4. Quick Check:

    Pipeline = Pass output to next command [OK]
Hint: Pipeline passes output to next command in sequence [OK]
Common Mistakes:
  • Thinking pipeline runs commands in parallel
  • Confusing pipeline with comments
  • Assuming pipeline creates variables
2. Which of the following is the correct syntax to list all processes and then sort them by CPU usage using the pipeline?
easy
A. Get-Process Sort CPU
B. Get-Process | Sort-Object CPU
C. Get-Process | Sort-Object -CPU
D. Get-Process Sort-Object CPU

Solution

  1. Step 1: Identify correct pipeline usage

    The pipeline operator | must connect commands properly; Get-Process | Sort-Object CPU uses it correctly.
  2. Step 2: Check Sort-Object parameters

    Sorting by property CPU is done with Sort-Object CPU, which Get-Process | Sort-Object CPU uses correctly.
  3. Final Answer:

    Get-Process | Sort-Object CPU -> Option B
  4. Quick Check:

    Correct pipeline and sorting syntax = Get-Process | Sort-Object CPU [OK]
Hint: Use | between commands and correct parameter names [OK]
Common Mistakes:
  • Omitting the pipeline operator
  • Using wrong parameter syntax like -CPU
  • Using non-existent commands like Sort CPU
3. What is the output of this PowerShell command?
Get-Process | Where-Object { $_.CPU -gt 100 } | Select-Object -First 1 -Property ProcessName
medium
A. The name of the first process with CPU usage greater than 100
B. A list of all processes with CPU usage less than 100
C. An error because of incorrect pipeline usage
D. The total CPU usage of all processes

Solution

  1. Step 1: Analyze the pipeline commands

    Get-Process gets all processes, Where-Object { $_.CPU -gt 100 } filters those with CPU > 100.
  2. Step 2: Understand the selection

    Select-Object -First 1 -Property ProcessName picks the first such process and shows its name.
  3. Final Answer:

    The name of the first process with CPU usage greater than 100 -> Option A
  4. Quick Check:

    Pipeline filters then selects first matching process name [OK]
Hint: Filter with Where-Object, then select first with Select-Object [OK]
Common Mistakes:
  • Confusing CPU greater than with less than
  • Expecting a list instead of one item
  • Thinking pipeline causes errors here
4. Identify the error in this pipeline command:
Get-Service | Where-Object Status -eq 'Running' | Select Name
medium
A. Select should be Select-Object, not Select.
B. Get-Service cannot be piped to Where-Object.
C. The comparison operator should be inside the script block {} in Where-Object.
D. The pipeline operator is missing.

Solution

  1. Step 1: Check Where-Object syntax

    The condition must be inside a script block: { $_.Status -eq 'Running' }. The given command misses the braces.
  2. Step 2: Verify other parts

    Select is an alias for Select-Object, so it's valid. Get-Service can be piped. Pipeline operator is present.
  3. Final Answer:

    The comparison operator should be inside the script block {} in Where-Object. -> Option C
  4. Quick Check:

    Where-Object needs script block for conditions [OK]
Hint: Put conditions inside {} for Where-Object [OK]
Common Mistakes:
  • Omitting braces {} in Where-Object
  • Thinking Select is invalid
  • Assuming pipeline operator is missing
5. You want to get the top 3 services sorted by their status alphabetically, but only those that are running. Which pipeline command achieves this?
hard
A. Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Status | Select-Object -First 3
B. Get-Service | Sort-Object Status | Select-Object -First 3 | Where-Object { $_.Status -eq 'Running' }
C. Get-Service | Select-Object -First 3 | Where-Object { $_.Status -eq 'Running' } | Sort-Object Status
D. Get-Service | Where-Object Status -eq 'Running' | Select-Object -First 3 | Sort-Object Status

Solution

  1. Step 1: Filter running services first

    Use Where-Object { $_.Status -eq 'Running' } to keep only running services.
  2. Step 2: Sort filtered services by Status

    Then sort them alphabetically with Sort-Object Status.
  3. Step 3: Select the first 3 services

    Finally, pick the top 3 with Select-Object -First 3.
  4. Final Answer:

    Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Status | Select-Object -First 3 -> Option A
  5. Quick Check:

    Filter, then sort, then select top 3 [OK]
Hint: Filter first, then sort, then select top items [OK]
Common Mistakes:
  • Sorting before filtering changes results
  • Selecting before filtering loses data
  • Missing braces in Where-Object
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard