Select Properties with Select-Object: Show Only What Matters
Too much information clutters your screen. Select-Object shows only the columns you care about.
How It Works
Select-Object picks specific properties from results and hides the rest. Imagine a spreadsheet with 50 columns—Select-Object lets you show only the 3 columns you actually need.
This makes output cleaner and easier to read. It also helps you understand what data is available.
Code Examples
Show Specific Columns
# Show only Name and Size (hides other properties)
Get-ChildItem -File | Select-Object Name, Length
# Output:
# Name Length
# ---- ------
# report.txt 4521
# document.xlsx 12048
Rename Columns While Showing
# Show Length as 'Size in bytes'
Get-ChildItem -File | Select-Object Name, @{Name="SizeInBytes";Expression={$_.Length}}
# Output shows 'SizeInBytes' instead of 'Length'
# Much clearer for other people reading your script!
Show First N Items
# Show only the first 5 files
Get-ChildItem | Select-Object -First 5
# Show the last 10
Get-ChildItem | Select-Object -Last 10
Combine with Sorting
# Show name and size, sorted by size (biggest first)
Get-ChildItem -File | Select-Object Name, Length | Sort-Object Length -Descending
# Result: Cleanest output showing biggest files first
Most Used Options
- Name, Length - Show these specific properties
- -First 5 - Show only first 5 items
- -Last 10 - Show only last 10 items
- @{Name='NewName';Expression={...}} - Rename a property while displaying
The Trick: Power Usage
Create readable process reports:
# Show process names and memory, sorted by memory usage
Get-Process | Select-Object Name, @{Name="MemoryMB";Expression={$_.Memory/1MB}} | Sort-Object MemoryMB -Descending
# Shows processes from most to least memory-hungry
# Much easier to read than raw data!
Pipeline cleanup pattern:
Get-ChildItem | Where-Object {$_.Length -gt 10MB} | Select-Object Name, Length | Sort-Object Length -Descending
# 1. Get all files
# 2. Filter to only big ones
# 3. Show only name and size
# 4. Sort by size
Learn It Through Practice
Stop reading and start practicing right now:
The interactive environment lets you type these commands and see real results immediately.
Next in PowerShell for Beginners
This is part of the PowerShell for Beginners series:
- Getting Started - Your first commands
- Command Discovery - Find what exists
- Getting Help - Understand commands
- Working with Files - Copy, move, delete
- Filtering Data - Where-Object and Select-Object
- Pipelines - Chain commands together
Related Resources
Summary
You now understand:
- How this command works
- The most common ways to use it
- One powerful trick to level up
- Where to practice hands-on
Practice these examples until they feel natural. Then tackle the next command in the series.
Ready to practice? Head to the interactive environment and try these commands yourself. That's how it sticks!
What PowerShell commands confuse you? Drop it in the comments!
Top comments (0)