Get-ADComputer and MemberOf

I am very new to Powershell and I am having trouble using the Get-ADUserand cmdlets GetADComputer.

I try to use Get-ADComputerand Get-ADUserto extract memberOffrom Active Directory all users and computers. It seems that he receives information from users and computers that are in 2 or more groups. Any users / computers that are in only 1 group do not display anything.

For example: if UserA is in the Administrators group, I do not get an exit when I use MemberOf. But if User2 is in the Administrators and Domain Admins, I get some output. However, he will output only one of these groups.

Get-ADGroup does the same.

This is normal? I can’t imagine what it was.

Here is my code:

Get-ADUser -Filter * -Properties * | Select-Object -Property Name,MemberOf | Sort-Object -Property Name

thank

+3
source share
1 answer

Your problem is that the main group is not part of the attribute memberOf.

So try the following:

Get-ADUser -Filter * -Properties * | Select-Object -Property Name,MemberOf,PrimaryGroup | Sort-Object -Property Name

You will find a deeper explanation in this answer .

+4
source

All Articles