0
0
PowerShellscripting~30 mins

Where-Object for filtering in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Filtering Data with Where-Object in PowerShell
📖 Scenario: You work in a small store and have a list of products with their prices. You want to find which products cost less than $20 to decide what to promote in a sale.
🎯 Goal: Build a PowerShell script that filters a list of products to show only those priced below $20 using Where-Object.
📋 What You'll Learn
Create a list of products with their prices as objects
Set a price limit variable to 20
Use Where-Object to filter products cheaper than the price limit
Display the filtered products
💡 Why This Matters
🌍 Real World
Filtering lists of items by conditions is common in managing inventories, logs, or user data.
💼 Career
Knowing how to filter data with PowerShell helps automate tasks in IT support, system administration, and data processing.
Progress0 / 4 steps
1
Create the product list
Create a variable called products that holds an array of three objects. Each object should have two properties: Name and Price. Use these exact entries: Name = 'Pen', Price = 5, Name = 'Notebook', Price = 15, Name = 'Backpack', Price = 45.
PowerShell
Need a hint?

Use @( ... ) to create an array and @{Name=''; Price=} to create objects.

2
Set the price limit
Create a variable called priceLimit and set it to 20.
PowerShell
Need a hint?

Just assign the number 20 to $priceLimit.

3
Filter products using Where-Object
Create a variable called cheapProducts that stores the result of filtering $products using Where-Object. Keep only products where Price is less than $priceLimit. Use the syntax: $products | Where-Object { $_.Price -lt $priceLimit }.
PowerShell
Need a hint?

Use Where-Object with a script block that checks if Price is less than $priceLimit.

4
Display the filtered products
Use Write-Output to print the $cheapProducts variable.
PowerShell
Need a hint?

Just write Write-Output $cheapProducts to show the filtered list.