I've an array of objects:
$list = @( `
@{title='First';guid='0118B390-3AF5-406E-920D-FE140392584D'}, `
@{title='Second';guid='2C78DA61-B6EF-4E4E-8FF8-4A95D75C8188'}, `
@{title='Third';guid='0EDC361C-862E-41FC-8A60-870CADC17EC5'} `
)
I want to use the guid to look up and return a title. All I want is the value, I don't want to return an object. For example, if looking up guid '2C78DA61-B6EF-4E4E-8FF8-4A95D75C8188' I just want to return a string value 'Second', rather than an object with a property whose value is 'Second'.
How can I do this?
I've tried the following:
$list | where guid -eq '2C78DA61-B6EF-4E4E-8FF8-4A95D75C8188'
which returns a hash table
and
$list | where guid -eq '2C78DA61-B6EF-4E4E-8FF8-4A95D75C8188' | select {$_.title}
which returns a PSObject with a {$_.title} NoteProperty.
The following two attempts work:
($list | where guid -eq '2C78DA61-B6EF-4E4E-8FF8-4A95D75C8188' `
| select {$_.title}).{$_.title}
($list | where guid -eq '2C78DA61-B6EF-4E4E-8FF8-4A95D75C8188' `
| select @{Name="result";Expression={$_.title}}).result
However, they're both ugly. Is there a better way of returning just the value?