0
0
PowerShellscripting~5 mins

Where-Object for filtering in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the <code>Where-Object</code> cmdlet do in PowerShell?

Where-Object filters objects from a collection based on a condition you specify. It only passes through objects that meet the condition.

Click to reveal answer
beginner
How do you write a simple Where-Object filter to get numbers greater than 10 from a list?

Use: ... | Where-Object { $_ -gt 10 }. Here, $_ is the current item, and -gt means 'greater than'.

Click to reveal answer
beginner
What does $_ represent inside the Where-Object script block?

$_ is a variable that holds the current object being tested in the filter. Think of it as 'this item' in the list.

Click to reveal answer
intermediate
Can Where-Object filter based on object properties? Give an example.

Yes. For example, to filter processes using more than 100MB memory: Get-Process | Where-Object { $_.WorkingSet -gt 100MB }.

Click to reveal answer
intermediate
What is the difference between Where-Object and ForEach-Object?

Where-Object filters items based on a condition. ForEach-Object runs a command on each item but does not filter.

Click to reveal answer
What does Where-Object { $_ -eq 5 } do?
ASelects objects equal to 5
BSelects objects not equal to 5
CSelects all objects
DDeletes objects equal to 5
In Where-Object, what does $_ stand for?
AThe script name
BA global variable
CThe last command run
DThe current object in the pipeline
Which operator filters objects greater than 100 in Where-Object?
A-lt
B-eq
C-gt
D-ne
How would you filter files larger than 1MB using Where-Object?
AGet-ChildItem | Where-Object { $_ -eq 1MB }
BGet-ChildItem | Where-Object { $_.Length -gt 1MB }
CGet-ChildItem | Where-Object { $_.Size -lt 1MB }
DGet-ChildItem | Where-Object { $_.Length -lt 1MB }
Which cmdlet would you use to run a command on each object without filtering?
AForEach-Object
BWhere-Object
CSelect-Object
DSort-Object
Explain how Where-Object works to filter items in a PowerShell pipeline.
Think about how you pick only certain fruits from a basket based on color.
You got /4 concepts.
    Describe how to filter processes that use more than 50MB of memory using Where-Object.
    Remember to check the property that shows memory usage.
    You got /4 concepts.