Converting Custom Object Arrays To String Arrays In Powershell


Answer :

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"(...)" or "($_.Option)".



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable