ExpandProperty to the Rescue

by Mar 26, 2010

You will find that Select-Object is often used to select object properties and discard unneeded information:

Get-Process | Select-Object Name, Company

In addition, Select-Object also does another important job by replacing the original object with one of its properties. This is a big difference. Let's say you need a list of running processes and just want their names. If you did it like this, you would get objects with a name property (which is why PowerShell displays a column header):

Get-Process | Select-Object Name

You can add -ExpandProperty if you just want the names as strings:

Get-Process | Select-Object -ExpandProperty Name

Twitter This Tip! ReTweet this Tip!