PowerShell – Domain Users Group Missing from PowerShell AD Query

active-directorygroupspowershell

I ran the following PowerShell script to compare a list of groups….

$dasMem = Get-ADUser -Server "<some-srv>" -Identity "<some-usr>" -Properties MemberOf | Select MemberOf
$blahx = $dasMem.MemberOf | % { $_ -replace "^CN=", "" } | % { $_ -replace ",.*$", "" } | sort
$blahx

When I got the list, I ended up with a missing group, Domain users which I believe is a standard default group. Is there any reason why it's missing when I pull the script?

To be clear I was able to see the group in Active Directory Users and Computers, but not from my script above.

Best Answer

As silly as it sounds, it's because Domain Users is not actually in the memberOf attribute. You can verify in ADUC by turning on View - Advanced Features, going to the Attributes tab on your object and opening the memberOf attribute (not the "Member Of" tab).

The "Member Of" tab you see on an object's properties in ADUC is actually a conglomeration of the memberOf attribute and the primaryGroupID attribute. By default, users in AD get their Domain Users membership via this primaryGroupID attribute rather than an entry in memberOf. Though it's possible to change the primaryGroupID, most people don't.