Challenge - 5 Problems
PowerShell Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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 }
Attempts:
2 left
💡 Hint
Think about filtering even numbers first, then multiplying each by 10.
✗ Incorrect
The pipeline first selects even numbers from 1 to 5 (2 and 4), then multiplies each by 10, resulting in 20 and 40.
💻 Command Output
intermediate2: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
Attempts:
2 left
💡 Hint
Filter words longer than 5 letters, then sort alphabetically.
✗ Incorrect
Only 'banana' and 'cherry' have length greater than 5. Sorting alphabetically gives 'banana' then 'cherry'.
🔧 Debug
advanced2: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 }
Attempts:
2 left
💡 Hint
Check the operation inside ForEach-Object carefully.
✗ Incorrect
Dividing any number by zero causes a runtime error in PowerShell, so the pipeline fails at ForEach-Object.
🚀 Application
advanced2: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?
Attempts:
2 left
💡 Hint
Filter first, then sort descending by size.
✗ Incorrect
Filtering first reduces items to those larger than 1MB, then sorting descending shows largest first. Option D sorts first then filters, which is less efficient but works; however, the question expects filtering first.
🧠 Conceptual
expert2:00remaining
What is the main benefit of using pipelines in PowerShell scripting?
Why do PowerShell users prefer pipelines (|) when writing scripts?
Attempts:
2 left
💡 Hint
Think about how data flows between commands.
✗ Incorrect
Pipelines let you connect commands so the output of one command flows directly as input to the next, making scripts simpler and efficient.