Maybe a dumb question, but I can't really understand why this is happening.
Simple PS script - to count AD user groups. But for users who is member of the primary group only, the counter is empty. When I query the same user with a command manually - the counter works.
If a user is a member of any other group, then the script works fine.
As an example:
...
foreach ($user in $users)
{
$SAM = $user.SamAccountName
$groups = Get-ADPrincipalGroupMembership -Identity $SAM | select name
$SAM
$groups.count
...
Output
SomeUser
2
SomeUser1
SomeUser2
SomeUser3
37
...
If I query SomeUser1 manually
(Get-ADPrincipalGroupMembership -Identity SomeUser1 | select name).count
1