PowerShell Lesson 3: The Pipeline — Filter, Sort, Select

📎 This article includes 3 downloadable practice files ↓

⏱ 1 min read

📘 PowerShell Beginner Course · Lesson 3 of 6

PowerShell passes objects (with properties) through the pipeline, not plain text. That makes filtering and sorting reliable.

“`powershell
$orders = Import-Csv .\sales.csv
$orders | Where-Object { [int]$_.qty -ge 5 } | Measure-Object
$orders | Sort-Object { [int]$_.qty * [int]$_.rate } -Descending | Select-Object -First 3 order_id, region
$orders | Group-Object region | ForEach-Object { “{0}: {1} orders” -f $_.Name, $_.Count }
“`

Comparison operators: -eq -ne -gt -ge -lt -le -like -match. CSV values arrive as text, so cast with [int] before comparing numbers.

💡 Pipe anything to Get-Member to see its properties and methods: Get-ChildItem | Get-Member.

Practice

Put sales.csv next to the script and run it.

📎 Practice files for this article

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *