Picking Columns: Select-Object
Select-Object keeps only the properties you name with -Property, only the first or last few objects with -First and -Last, and with -ExpandProperty hands you one property's plain values, ready to save as a list.
Apprentice · PowerShell · Updated
After this lesson you can
- Choose which properties to show, and how many objects, with Select-Object -Property, -First and -Last
- Get one property's plain values with Select-Object -ExpandProperty
Key takeaways
Select-Object -Property Name, Lengthkeeps only the properties you name, in that order, even ones the table never shows.-First 3keeps the first three objects and-Last 3the last three, in the order they arrive.-ExpandProperty Namegives the plain values of one property, with no column heading: a list you can save or paste.- A misspelled property name gives an empty column, not an error.
A friend wants the list of photos from the trip, with their sizes, so they can pick which ones to ask for. A manager asks for the names of the files in a shared folder: names only, no dates or sizes. A folder of 600 files has you wondering what kind of files they are, and the first few would tell you. Get-ChildItem always shows the same four columns, and every row. Clicking through File Explorer's column settings, then copying names one at a time, is slow, and a slip is hard to spot. Select-Object keeps the facts you ask for and the number of rows you ask for, and nothing else.
This lesson uses the vacation-photos folder from What an Object Is: Get-Member. If you don't have it, run that lesson's practice-folder lines first.
The columns you want: -Property
Think of photocopying the library card with only the lines you need on it. Select-Object -Property makes that copy for each object: a new, smaller object holding only the properties you name. List them with commas between them (read the comma "and"):
Get-ChildItem | Select-Object -Property Name, Length
Name Length
---- ------
captions.txt 94
clock-tower.jpg 4210
falls.jpg 5180
sandcastle.jpg 2875
summit.jpg 3620
sunset.jpg 3150
The | hands every file Get-ChildItem found to Select-Object, whole object and all, so it can pick properties from each one. You can name any property Get-Member lists, in any order, including ones the normal table never shows. The word -Property can be left out, too, since it's the value Select-Object expects first:
Get-ChildItem | Select-Object Name, Extension, CreationTime
Name Extension CreationTime
---- --------- ------------
captions.txt .txt 7/18/2026 9:40:00 PM
clock-tower.jpg .jpg 7/18/2026 9:40:00 PM
falls.jpg .jpg 7/18/2026 9:40:00 PM
sandcastle.jpg .jpg 7/18/2026 9:40:00 PM
summit.jpg .jpg 7/18/2026 9:40:00 PM
sunset.jpg .jpg 7/18/2026 9:40:00 PM
A misspelled name doesn't stop anything. Select-Object -Property Name, Size shows a Size column with nothing in it, because a file has no property called Size: its size is Length. An empty column is the sign to check the name with Get-Member.
The first few, or the last: -First and -Last
-First keeps the first so many objects, and -Last the last so many:
Get-ChildItem | Select-Object -First 2
Directory: C:\Users\Sam\terminal-practice\vacation-photos
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 7/18/2026 9:40 PM 94 captions.txt
-a--- 7/18/2026 9:40 PM 4210 clock-tower.jpg
With no -Property, the objects are the files themselves, so they show the usual four columns. Mix the two to choose rows and columns at once:
Get-ChildItem | Select-Object -Last 1 -Property Name, Length
Name Length
---- ------
sunset.jpg 3150
"First" and "last" mean in the order the objects arrive, and Get-ChildItem lists by name. So -First 1 is the first name in alphabetical order, not the biggest file or the newest one. Putting the biggest first is sorting, which Sorting: Sort-Object, in the next chapter, adds in front of -First.
Only the values: -ExpandProperty
-Property Name gives you objects with one property, shown as a table with a Name heading. Sometimes you want the names themselves: a list to paste into a message or save to a file. -ExpandProperty (read "expand property") takes the value off the card and hands you only that:
Get-ChildItem | Select-Object -ExpandProperty Name
captions.txt
clock-tower.jpg
falls.jpg
sandcastle.jpg
summit.jpg
sunset.jpg
No heading, no dashes: six strings of text. Get-Member shows the difference. After -Property Name the TypeName is Selected.System.IO.FileInfo, a smaller copy of a file's card; after -ExpandProperty Name it's System.String, plain text. -ExpandProperty takes one property name only.
Plain text is what a file needs, so the list goes straight into one with Set-Content, from Writing to Files: Set-Content, Add-Content and >. .. puts it in the folder above, so the photo folder stays as it is:
Get-ChildItem | Select-Object -ExpandProperty Name | Set-Content ..\photo-list.txt
Get-Content ..\photo-list.txt
captions.txt
clock-tower.jpg
falls.jpg
sandcastle.jpg
summit.jpg
sunset.jpg
The same for running programs
Select-Object works on any object. Here is the PowerShell window you're typing in, with three of its 50-plus properties:
Get-Process -Id $PID | Select-Object -Property Name, Id, StartTime
Name Id StartTime
---- -- ---------
pwsh 52216 11/9/2026 4:49:52 AM
Your Id and time will differ. Windows PowerShell 5.1 works the same way, and so does PowerShell on a Mac or Linux.
Try it. List the first three file names in your own Downloads folder with Get-ChildItem "$HOME\Downloads" -File | Select-Object -First 3 -ExpandProperty Name. Then show their names and LastWriteTime instead.
Check yourself
2 questions to try on the lesson page.
So what
Select-Object turns "everything about everything" into exactly the facts and rows you need, and with -ExpandProperty into a plain list you can save or send.