VOOZH about

URL: https://dev.to/arnostorg/select-properties-with-select-object-show-only-what-matters-46bi

⇱ Select Properties with Select-Object: Show Only What Matters - DEV Community


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-ObjectName,Length# Output:# Name Length# ---- ------# report.txt 4521# document.xlsx 12048

Rename Columns While Showing

# Show Length as 'Size in bytes'Get-ChildItem-File|Select-ObjectName,@{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 filesGet-ChildItem|Select-Object-First5# Show the last 10Get-ChildItem|Select-Object-Last10

Combine with Sorting

# Show name and size, sorted by size (biggest first)Get-ChildItem-File|Select-ObjectName,Length|Sort-ObjectLength-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 usageGet-Process|Select-ObjectName,@{Name="MemoryMB";Expression={$_.Memory/1MB}}|Sort-ObjectMemoryMB-Descending# Shows processes from most to least memory-hungry# Much easier to read than raw data!

Pipeline cleanup pattern:

Get-ChildItem|Where-Object{$_.Length-gt10MB}|Select-ObjectName,Length|Sort-ObjectLength-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:

πŸ‘‰ Practice on your browser

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:

  1. Getting Started - Your first commands
  2. Command Discovery - Find what exists
  3. Getting Help - Understand commands
  4. Working with Files - Copy, move, delete
  5. Filtering Data - Where-Object and Select-Object
  6. 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!