What does -ExpandProperty do ?

Sorry all for the very silly question. Dont beat me up in here too badly all PS Experts PLEASE!!!


I am trying to find a good explanation of the -ExpandProperty parameter but as yet have yet to find one online. Can someone in here please explain the above-mentioned???


Thank you and God bless you!!!

Some of the examples here are pretty good: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-6

Basically, it takes whatever object(s) or value(s) that are in the targeted property and gives you that back, effectively removing one “layer” of the object.

If you use it in combination with the usual -Property parameter, then the properties specified by -Property from the original object are added to the object(s)/value(s) before they are given back.

$Object = [PSCustomObject]@{ PropA = 10; PropB = [PSCustomObject]@{ SubPropA = 1 } }

$Object | Select-Object -ExpandProperty PropA 
# Output: 10 

$Object | Select-Object -Property PropA -ExpandProperty PropB
# Output: an object with PropA and SubPropA as first-level properties:
# PropA  SubPropA
# -----  --------
# 10     1


I most frequently use this to get a list of AD groups a user is a member of.

get-aduser USERID -properties memberof | select-object -expandproperty memberof

Thank you so much for the response.


Have a blessed day!!!

(edit: all those responses while I was typing mine!)

i’ll rookie attempt to illustrate this with an example as I know it. the experts can beat me up, too.

say I do:

$thing = get-item c:\users | select name

$thing is now an object, with a property called “name”, that has a value of “users.”
<p style=“padding-left: 40px;”>Name

if I want to use the string ‘users’ out of this later, I have to use “the value of the ‘name’ property of the $thing object,” aka $thing.name

but if instead I do:

$thing = get-item c:\users | select -expandproperty name

$thing is just the string “users” with no column headings, and I don’t have to call a property later, I can just use $thing.

Excellent explanation. Thank you SOOOOOO Much!!!

Yes I noticed the heading disappearing as well when using the “-expand” parameter.

I truly appreciate yours and the preceding two responses as well.

I wasnt sure how my question would be taken as it definitely shows my “noob-mentality”.


Thanks again, and God bless you!!!