0
0
PowerShellscripting~20 mins

Where-Object for filtering in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Where-Object Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of filtering numbers greater than 5
What is the output of this PowerShell command?
1..10 | Where-Object { $_ -gt 5 }
PowerShell
1..10 | Where-Object { $_ -gt 5 }
A
6
7
8
9
10
B
1
2
3
4
5
6
C
5
6
7
8
9
10
D
1
2
3
4
5
Attempts:
2 left
💡 Hint
Remember, Where-Object filters items where the condition is true.
💻 Command Output
intermediate
2:00remaining
Filtering strings containing 'a'
What is the output of this PowerShell command?
@('apple','banana','cherry','date') | Where-Object { $_ -like '*a*' }
PowerShell
@('apple','banana','cherry','date') | Where-Object { $_ -like '*a*' }
A
banana
cherry
date
B
apple
banana
date
C
apple
cherry
D
cherry
date
Attempts:
2 left
💡 Hint
The -like operator checks if the string contains the pattern.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in filtering
Which option contains a syntax error in using Where-Object to filter even numbers from 1 to 5?
PowerShell
1..5 | Where-Object { $_ % 2 -eq 0 }
A1..5 | Where-Object { $_ % 2 = 0 }
B} 0 qe- 2 % _$ { tcejbO-erehW | 5..1
C1..5 | Where-Object { $_ % 2 -eq 0 }
D..5 | Where-Object { $_ % 2 -eq 0 }
Attempts:
2 left
💡 Hint
Check the operator used for comparison.
🔧 Debug
advanced
2:00remaining
Why does this filter return no results?
Given this command:
@('cat','dog','bird') | Where-Object { $_ -ceq 'Cat' }

Why does it return no output?
PowerShell
@('cat','dog','bird') | Where-Object { $_ -ceq 'Cat' }
ABecause -ceq operator is invalid here
BBecause the array is empty
CBecause PowerShell -ceq string comparison is case-sensitive
DBecause the script block is missing a return statement
Attempts:
2 left
💡 Hint
Check the case sensitivity of the comparison operator used.
🚀 Application
expert
3:00remaining
Filter processes using Where-Object with multiple conditions
Which command filters processes with CPU usage greater than 100 and process name starting with 's' (case-insensitive)?
AGet-Process | Where-Object { $_.CPU -gt 100 -and $_.Name -like 's*' }
BGet-Process | Where-Object { $_.CPU -gt 100 -or $_.Name -ilike 's*' }
CGet-Process | Where-Object { $_.CPU > 100 -and $_.Name -like 's*' }
DGet-Process | Where-Object { $_.CPU -gt 100 -and $_.Name -ilike 's*' }
Attempts:
2 left
💡 Hint
Use the correct operator for case-insensitive matching and logical AND.