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


let's have array of objects $objects. let's these objects have "name" property.

this want

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

this works, can done in better way?

if like:

 $results = objects | select name 

$results array of objects having name property. want $results contain array of names.

is there better way?

i think might able use expandproperty parameter of select-object.

for example, list of current directory , have name property displayed, 1 following:

ls | select -property name 

this still returning directoryinfo or fileinfo objects. can inspect type coming through pipeline piping get-member (alias gm).

ls | select -property name | gm 

so, expand object of type of property you're looking at, can following:

ls | select -expandproperty name 

in case, can following have variable array of strings, strings name property:

$objects = ls | select -expandproperty name 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -