0
0
PowerShellscripting~10 mins

Where-Object for filtering in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to filter processes with CPU usage greater than 100.

PowerShell
Get-Process | Where-Object { $_.CPU [1] 100 }
Drag options to blanks, or click blank then click option'
A-gt
B-lt
C-ne
D-eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' which means 'less than' and would filter the wrong processes.
Using '-eq' which means 'equals' and might filter too few processes.
2fill in blank
medium

Complete the code to filter services that are running.

PowerShell
Get-Service | Where-Object { $_.Status [1] 'Running' }
Drag options to blanks, or click blank then click option'
A-lt
B-ne
C-eq
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ne' which means 'not equal' and would filter services that are not running.
Using '-lt' or '-gt' which are for numeric comparisons, not strings.
3fill in blank
hard

Fix the error in the code to filter files larger than 1MB.

PowerShell
Get-ChildItem | Where-Object { $_.Length [1] 1MB }
Drag options to blanks, or click blank then click option'
A-ne
B-gt
C-eq
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' which means 'less than' and would filter smaller files.
Using '-eq' which means 'equals' and might filter no files.
4fill in blank
hard

Fill both blanks to filter processes with names starting with 'S' and CPU usage less than 50.

PowerShell
Get-Process | Where-Object { $_.ProcessName [1] 'S*' -and $_.CPU [2] 50 }
Drag options to blanks, or click blank then click option'
A-like
B-eq
C-lt
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' instead of '-like' for pattern matching.
Using '-gt' instead of '-lt' for CPU comparison.
5fill in blank
hard

Fill all three blanks to create a dictionary of process names and their CPU usage, filtering only those with CPU usage greater than 10.

PowerShell
$result = @{ [1] = [2].ProcessName; [3] = [2].CPU } | Where-Object { [2].CPU -gt 10 }
Drag options to blanks, or click blank then click option'
AName
B$process
CCPU
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or keys.
Using '-lt' instead of '-gt' for filtering CPU usage.