Converting Custom Object arrays to String arrays in Powershell
This will give you what you want:
$strArray = $ms | Foreach {"$($_.Option)$($_.Title)"}
Select-Object is kind of like an SQL SELECT. It projects the selected properties onto a new object (pscustomobject in v1/v2 and Selected.<orignalTypeName> in V3). Your second approach doesn't work, because $_.Option
in a string will only "interpolate" the variable $_
. It won't evaluate the expression $_.Option
.
You can get double-quoted strings to evaluate expressions by using subexpressions, for example, "$(...)" or "$($_.Option)".