Objects
By the end of this lesson you'll be able to filter, sort, reshape, and summarise live system data using PowerShell's object pipeline — the one feature that makes it far more powerful than a traditional text-based shell.
Learn Python, JavaScript, Java and more with free interactive lessons, real projects and AI-powered help. Beginner-friendly.
Part of the free Powershell course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
1. The Object Pipeline
In a traditional shell the pipe | passes text , so the next command must re-parse that text every time. PowerShell's pipe passes objects — structured .NET values with named properties (like Name , CPU , Id ) and methods. That single difference is the whole point of the language: you filter, sort, and select by property name instead of counting columns. Where-Object keeps or drops objects, Sort-Object orders them, and Select-Object picks the columns you care about. Read this worked example, then run it.
Order matters and reads left to right: filter first so later steps do less work, then sort, then select. The Where-Object CPU -gt 1 form (property, operator, value) is the easy way to filter on a single property — no $_ needed.
2. Discover Anything with Get-Member
You never have to guess what an object can do. Pipe any object into Get-Member (alias gm ) and it lists every property and method, with types. Properties are the data ( Name , CPU ); methods are actions you call with () ( ToUpper() , GetType() ). This is the most important habit in PowerShell — when you're stuck, Get-Member tells you exactly what's available.
Notice ... inside the string — that's a subexpression : it runs code and drops the result into the text. Use it whenever you need a property or a method call inside "double quotes" .
The pipeline below is almost done. Fill in the two ___ blanks with the property name to filter and sort on, then run it and check your output against the expected lines.
3. ForEach-Object and the $_ Variable
ForEach-Object (alias % ) runs a script block — code in {' curly braces '} — once for every object in the pipeline. Inside that block, $_ (also written $PSItem ) is the current object , exactly like "this item" in a loop. The same $_ appears in any Where-Object {' ... '} script block too. Get comfortable with it now: $_ is everywhere in PowerShell.
Fill in the one blank so each price is multiplied by 1.2 (adding 20% tax). The hint tells you what ___ should be.
4. Calculated Properties
Select-Object doesn't only pick existing columns — it can build new ones . A calculated property is a small hashtable with two keys: Name (the column label) and Expression (a script block that computes the value, using $_ for the current object). This is how you turn raw bytes into megabytes, or a date into "days ago", right in the pipeline.
5. Group-Object & Measure-Object
Because the pipeline carries real data, you can do analysis without exporting to a spreadsheet. Group-Object buckets objects by a property (how many per region?). Measure-Object computes statistics in a single pass: -Sum , -Average , -Maximum , -Minimum , and a plain count. Together they answer real questions straight from the shell.
Here's the same job done the bash way (slicing text with awk ) versus the PowerShell way (naming a property). The bash version breaks the moment a column shifts or a name contains a space; the PowerShell version can't, because it never looks at text positions at all.
No blanks this time — just a brief and an outline. Build the full pipeline yourself: filter, sort, then select with a calculated Status column. Run it and check your output against the expected lines in the comments.
Practice quiz
What does the PowerShell pipeline pass between cmdlets?
- Structured .NET objects
- Plain text strings
- File handles
- JSON only
Answer: Structured .NET objects. PowerShell pipes real objects with named properties, not re-parsed text.
Which cmdlet keeps only objects that match a condition?
- Select-Object
- Where-Object
- Sort-Object
- Group-Object
Answer: Where-Object. Where-Object filters rows, keeping objects that match the condition.
Which cmdlet picks or computes which columns to keep?
- Where-Object
- Measure-Object
- Select-Object
- Format-Table
Answer: Select-Object. Select-Object chooses properties and can create calculated ones.
Inside a script block, what does $_ represent?
- The last error
- The script name
- An empty value
- The current pipeline object
Answer: The current pipeline object. $_ (also $PSItem) is the current object flowing through the pipeline.
Which cmdlet lists an object's properties and methods?
- Get-Member
- Get-Property
- Get-Command
- Get-Help
Answer: Get-Member. Get-Member (alias gm) reveals every property and method of an object.
How is a calculated property defined in Select-Object?
- A simple string label
- A hashtable with Name and Expression keys
- An array of values
- A switch parameter
Answer: A hashtable with Name and Expression keys. Use @{ Name='Label'; Expression={ ... } } to compute a new column.
Which cmdlet buckets objects by a property value?
- Sort-Object
- Group-Object
- Where-Object
- Measure-Object
Answer: Group-Object. Group-Object buckets objects by a shared property, like Region.
Which cmdlet computes Sum, Average, and Maximum in one pass?
- Count-Object
- Stat-Object
- Measure-Object
- Total-Object
Answer: Measure-Object. Measure-Object with -Sum -Average -Maximum gives stats in one pass.
Where should Format-Table go in a pipeline?
- First
- In the middle
- It can go anywhere
- Last, because it emits display objects
Answer: Last, because it emits display objects. Format-* cmdlets emit display objects, so they must come last.
How do you sort objects by CPU with the largest first?
- Sort-Object CPU -Descending
- Order CPU -Down
- Sort-Object -Reverse CPU
- Get-Process -Top CPU
Answer: Sort-Object CPU -Descending. Sort-Object CPU -Descending orders by the CPU property, highest first.