ExpandProperty to the Rescue

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!


Posted Mar 26 2010, 08:00 AM by ps1

Comments

Twitter Trackbacks for ExpandProperty to the Rescue - Power Tips - PowerShell.com [powershell.com] on Topsy.com wrote Twitter Trackbacks for ExpandProperty to the Rescue - Power Tips - PowerShell.com [powershell.com] on Topsy.com
on 03-26-2010 2:14 PM

Pingback from  Twitter Trackbacks for                 ExpandProperty to the Rescue - Power Tips - PowerShell.com         [powershell.com]        on Topsy.com

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.