5

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

1
  • 2
    @JohnLBevan Why not as a formal answer? You could line your pockets with up-votes. Commented Aug 15, 2017 at 12:01

1 Answer 1

9

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:

Sign up to request clarification or add additional context in comments.

2 Comments

Not to badmouth SS64, but why would people link there instead of to the actual documentation?
@AnsgarWiechers fair point; edited to include your MS link. I always go for SS64 first since generally I find those explanations/examples clearer (personal preference).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.