When I use the Select-Object Name
CmdLet it seems to create a new object with a single Name
property on it.
I often want to pipe this selection to other CmdLets but they often take just a string.
How can I easily get a bunch of objects and say "Select only property x and just the property values into an array or collection of just its values"?
You can use the ExpandProperty
parameter for this. This switch means that instead of returning an object with properties as listed on the (default) -Properties
parameter, the value of the single property listed under -ExpandProperty
parameter is returned.
NB: You can also use the alias, expand
for this parameter.
Example:
Get-Process | Select-Object -ExpandProperty ProcessName
Related documentation:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With