Powershell - Select the values of one property on all objects of an array

Posted by Sylvain Reverdy on Stack Overflow See other posts from Stack Overflow or by Sylvain Reverdy
Published on 2011-03-03T04:55:08Z Indexed on 2012/06/12 10:40 UTC
Read the original article Hit count: 243

Filed under:

Sorry, I'm still a noob on Powershell and I could not find an answer on Internet...

Let's say we have an array of objects $objects. Let's say these objects have a "Name" property.

This is what I want to do

 $results = @()
 $objects | %{ $results += $_.Name }

this works but can it be done on a better way?

If I do something like :

 $results = objects | Select Name

$results is an array of objects having a Name property. I want $results to contain an array of Names

So, is there a better way ?

Thx a lot

© Stack Overflow or respective owner

Related posts about powershell