Luke Puplett
Luke Puplett

Reputation: 45105

How to `select` to an array of strings

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"?

Upvotes: 5

Views: 3476

Answers (1)

JohnLBevan
JohnLBevan

Reputation: 24410

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:

Upvotes: 9

Related Questions