Select –ExpandProperty

Have you ever run a cmdlet and the goal is to get the value of a property from every object, but only the value (and not the headings that PowerShell also produces)?

What I mean is this…

If we run Get-Service, we’ll get output like this (I’m only showing a small portion of the output here).

Get-Service

Let’s run that same cmdlet again, this time only looking for services that start with the letter ‘a’.

Get-Service

But sometimes you don’t want to see that name column heading at all, you only want the actual results, in this case you want the name of any service starting with the letter ‘a’.

We could use a foreach loop and ask for the name property to be returned and this will work…

Get-Service

But a better option is to use the -expandproperty option of ‘select’.

And that will produce the desired results.

 
Comments

No comments yet.

Leave a Reply