Bird
Raised Fist0
PowerShellscripting~20 mins

Pipeline object flow in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
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 be the output?
PowerShell
1..5 | Where-Object { $_ % 2 -eq 0 } | ForEach-Object { $_ * 3 }
A2 4 6 8 10
B3 6 9 12 15
C6 12
D3 9 15
Attempts:
2 left
💡 Hint
Think about which numbers pass the filter and what happens next.
🧠 Conceptual
intermediate
1:30remaining
How does PowerShell pipeline pass data between commands?
In PowerShell, what is passed from one command to the next in a pipeline?
AText strings representing command output
BRaw bytes of command output
CFile paths of output files
DObjects representing data
Attempts:
2 left
💡 Hint
PowerShell pipelines are different from traditional text-based shells.
📝 Syntax
advanced
2:30remaining
Which pipeline syntax correctly filters and selects properties?
Which of the following PowerShell pipelines correctly filters processes with CPU usage over 100 and selects their names?
AGet-Process | Where-Object { $_.CPU -gt 100 } | Select-Object Name
BGet-Process | Where-Object CPU -gt 100 | Select-Object Name
CGet-Process | Where-Object { CPU > 100 } | Select-Object Name
DGet-Process | Where-Object { $_.CPU > 100 } | Select Name
Attempts:
2 left
💡 Hint
Remember the syntax for script blocks and property access in Where-Object.
🔧 Debug
advanced
2:00remaining
Why does this pipeline produce no output?
Given the pipeline below, why does it produce no output? Get-Service | Where-Object { $_.Status -eq 'Running' } | Where-Object { $_.Name -like 'X*' }
PowerShell
Get-Service | Where-Object { $_.Status -eq 'Running' } | Where-Object { $_.Name -like 'X*' }
ANo services have names starting with 'X' while running
BThe -like operator is case-sensitive and fails
CThe pipeline syntax is invalid and causes an error
DGet-Service does not output objects with Status property
Attempts:
2 left
💡 Hint
Check the actual service names and their statuses on your system.
🚀 Application
expert
2:30remaining
How many objects are passed through this pipeline?
How many objects does the pipeline output? 1..10 | ForEach-Object { if ($_ % 3 -eq 0) { $_ } }
PowerShell
1..10 | ForEach-Object { if ($_ % 3 -eq 0) { $_ } }
A10
B3
C0
D7
Attempts:
2 left
💡 Hint
Consider what happens when the if condition is false inside ForEach-Object.

Practice

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

Solution

  1. Step 1: Understand the pipeline operator

    The pipeline operator | connects commands by passing output from one as input to the next.
  2. Step 2: Identify its role in command chaining

    This allows commands to work together smoothly without temporary files or variables.
  3. Final Answer:

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

    Pipeline operator = passes output to next command [OK]
Hint: Pipeline | passes output to next command [OK]
Common Mistakes:
  • Thinking | is a comment symbol
  • Confusing | with variable assignment
  • Assuming | stops script execution
2. Which of the following is the correct syntax to filter files larger than 1MB using the pipeline?
easy
A. Get-ChildItem | Where-Object { $_.Length -gt 1MB }
B. Get-ChildItem | Where-Object { $_.Length > "1MB" }
C. Get-ChildItem | Where-Object { Length -gt 1MB }
D. Get-ChildItem | Where-Object Length -gt "1MB"

Solution

  1. Step 1: Check the correct property and operator usage

    In PowerShell, filter with Get-ChildItem | Where-Object { $_.Length -gt 1MB }. 1MB is a valid byte literal (1048576 bytes). Use $_. for current object and -gt for greater than.
  2. Step 2: Why others are incorrect

    B uses > "1MB" (string comparison, incorrect filtering). C omits $_. (undefined Length). D simplified syntax with "1MB" (string compare).
  3. Final Answer:

    Get-ChildItem | Where-Object { $_.Length -gt 1MB } -> Option A
  4. Quick Check:

    $_.Length -gt 1MB (numeric) [OK]
Hint: Use $_.Property inside braces for filtering [OK]
Common Mistakes:
  • Omitting $_. before property name
  • Quoting size (\"1MB\") causing string comparison
  • Misplacing parameters outside script block
3. What is the output of this command?
Get-Process | Where-Object { $_.CPU -gt 100 } | Select-Object -Property Name
medium
A. Empty list because no process uses CPU
B. List of all processes with CPU property
C. Error because CPU is not a valid property
D. List of process names using more than 100 CPU seconds

Solution

  1. Step 1: Filter processes by CPU usage

    The command filters processes where the CPU time is greater than 100 seconds.
  2. Step 2: Select only the Name property

    After filtering, it selects and outputs only the process names.
  3. Final Answer:

    List of process names using more than 100 CPU seconds -> Option D
  4. Quick Check:

    Filtering then selecting property = filtered names [OK]
Hint: Filter first, then select properties to see desired output [OK]
Common Mistakes:
  • Assuming CPU is not a valid property
  • Expecting full process details instead of just names
  • Thinking the output is empty without checking actual CPU usage
4. Identify the error in this pipeline:
Get-Service | Where-Object { $_.Status = 'Running' }
medium
A. Where-Object cannot be used with Get-Service
B. Missing pipeline operator (|) between commands
C. Using single equals (=) instead of comparison operator (-eq)
D. Incorrect property name 'Status'

Solution

  1. Step 1: Check the comparison operator in Where-Object

    The script uses = which is an assignment, not a comparison. PowerShell requires -eq for equality checks.
  2. Step 2: Confirm pipeline and property usage

    The pipeline operator is present and Status is a valid property of service objects.
  3. Final Answer:

    Using single equals (=) instead of comparison operator (-eq) -> Option C
  4. Quick Check:

    Use -eq for comparisons, not = [OK]
Hint: Use -eq for equality, not = inside script blocks [OK]
Common Mistakes:
  • Confusing = with -eq in conditions
  • Removing pipeline operator accidentally
  • Assuming property names are incorrect without checking
5. You want to list all files in a folder and its subfolders, sorted by size descending, but only show the top 5 largest files. Which pipeline command achieves this?
hard
A. Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 5
B. Get-ChildItem -Recurse | Sort-Object Length -Descending | Select-Object -First 5
C. Get-ChildItem -Recurse | Where-Object Length -gt 5 | Sort-Object Length
D. Get-ChildItem -Recurse | Select-Object -First 5 | Sort-Object Length -Descending

Solution

  1. Step 1: Include all files recursively

    Use -Recurse with Get-ChildItem to get files in all subfolders.
  2. Step 2: Sort files by size descending and select top 5

    Sort by Length descending, then select the first 5 files.
  3. Final Answer:

    Get-ChildItem -Recurse | Sort-Object Length -Descending | Select-Object -First 5 -> Option B
  4. Quick Check:

    Recurse + sort descending + select first 5 = correct pipeline [OK]
Hint: Recurse first, then sort descending, then select top items [OK]
Common Mistakes:
  • Forgetting -Recurse to include subfolders
  • Selecting top 5 before sorting
  • Using Where-Object incorrectly to filter by number
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