Run the following command:
Get-ADUser -properties MemberOf | select MemberOf | Format-List *
results in something like
Adi Inbar is correct. Let me expand on this by saying if you're having issues, often get-member
is very useful for figuring out what is going on.
PS C:\> ipmo ActiveDirectory
PS C:\> Get-ADUser testuser42 | select memberof | gm
TypeName: Selected.Microsoft.ActiveDirectory.Management.ADUser
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
memberof NoteProperty Microsoft.ActiveDirectory.Management.ADPropertyValueCollection memberof=Microsoft.ActiveDir...
Use Select-Object's -ExpandProperty switch:
Get-ADUser <username> -Properties MemberOf | select -ExpandProperty MemberOf
When you use Select-Object to filter for certain properties, it returns a PSCustomObject containing the specified properties of the object selected (or an array of PSCustomObjects, if multiple objects are selected). With -ExpandProperty, which may be used with only a single property, for each object selected it returns the object contained in the specified property.
So, with | select MemberOf
, what's being returned is a PSCustomObject whose sole property is the MemberOf property of the ADUser object returned by Get-ADUser, displayed in list format (in the same style as it would display the results if you were listing multiple properties of the object).
With | select -ExpandProperty MemberOf
, what's being returned is the ADPropertyCollection object which is contained in the MemberOf property (a collection of strings representing the DNs of the members), and that's the object that's displayed in list format.
BTW, I removed the | Format-List *
because it's superfluous in this case.