If you are interested, "primary" group membership in AD is determined by the primaryGroupToken attribute of the group object, and the primaryGroupID attribute of the user (or computer) object. PowerShell Get-ADGroup and ADUC do not reveal the value
of the primaryGroupToken attribute because it is operational (also called constructed). It is an integer, equal to the last digits (after the final dash) in the value of the SID property (or the objectSID attribute in Attribute Editor). Or you can retrieve
the value using dsquery *. The user object has the attribute primaryGroupID, also an integer. The value matches the primaryGroupToken attribute of the group the user has designated as their "Primary".
The primaryGroupToken of "Domain Users" is 513, and for "Domain Computers is 515 (because their RID values are "well-known"). If you need to check the "primary" group of a user, retrieve the value of the primaryGroupID
attribute. If the value is 513, the "primary" group of the user is "Domain Users". Do the same for computer objects and if primaryGroupID equals 515, then the "primary" group is "Domain Computers".
To find all users that have "Domain Users" as their "primary" group, you could use:
Get-ADUser -LDAPFilter "(primaryGroupID=513)" | Select distinguishedName
To check an individual user:
Get-ADUser -Identity jsmith -Properties primaryGroupID | Select Name, primaryGroupID
Unfortunately, you cannot filter on primaryGroupToken because it is operational. Special code techniques are required to find which group has a given value assigned to the primaryGroupToken attribute. The following isn't efficient (since it retrieve all
groups), but it works to find the group where primaryGroupToken is 514:
Get-ADGroup -Filter * | Where-Object {$_.SID -Like "*-514"}
The result will be "Domain Guests", which has another well-known RID.