When to use Select-Object’s -ExpandProperty

by Aug 1, 2011

Use Select-Object to determine which information in a result you are interested in. Here are three easy rules for its parameters:

Use -Property * when you want to see maximum information:

Get-Process | Select-Object -Property *

Use -Property a,b,c to select more than one column:

Get-Process | Select-Object -Property Name, Description, Company

Use -ExpandProperty Column to select exactly one column:

Get-Process | Select-Object -ExpandProperty Name

It does not make sense to preserve the column when you select only one column anyway, so use -ExpandProperty to remove the column and show only the actual column content.

 

Twitter This Tip!
ReTweet this Tip!