PowerShell – Get list of AD Groups for User

Use PowerShell Get-ADUser cmdlet get aduser object and using Memberof to get list of ad groups for user belongs to.

Let’s consider an example to understand how to get list of ad groups for users in PowerShell. You can get list of active directory groups user belongs to using get aduser memberof property and net user command.

There are different ways to get list of ad groups in PowerShell. Let’s see one by one with examples.

Get List of Ad Groups for User

Using PowerShell Get-ADUser cmdlet to get aduser specified by username and use MemberOf to get ad groups for user. Run below command

(Get-ADUser Toms –Properties MemberOf).MemberOf

In the above PowerShell script, Get-ADUser memberof attribute returns distinguished names of the ad groups to which this user belongs.

The output of above get aduser memberof command as below

CN=Group Policy Creator Owners,CN=Users,DC=SHELLPRO,DC=LOCAL
CN=Domain Admins,CN=Users,DC=SHELLPRO,DC=LOCAL
CN=Enterprise Admins,CN=Users,DC=SHELLPRO,DC=LOCAL
CN=Schema Admins,CN=Users,DC=SHELLPRO,DC=LOCAL
CN=Administrators,CN=Builtin,DC=SHELLPRO,DC=LOCAL

or you can use an alternate way to get list of ad groups using Get-ADGroup cmdlet as below

(Get-ADUser Toms –Properties MemberOf).memberof | Get-ADGroup | Select-Object name

In the above PowerShell command, Get-AdUser get aduser object specified for username and using Get-ADGroup cmdlet to get one or more groups users member of.

The output of above get aduser memberof command to get ad group name is as

name
----
Group Policy Creator Owners
Domain Admins
Enterprise Admins
Schema Admins
Administrators

Let’s consider an example to find my ad groups in active directory based on username ShellAdmin, using the above command

(Get-ADUser ShellAdmin –Properties MemberOf).memberof | Get-ADGroup | Select-Object name

In the above PowerShell script, Get-ADUser takes username ‘ShellAdmin’ and gets my ad groups I am member of and print list of ad groups on the console.

Net User to get list of ad groups for User

Use net dos command to get list of ad groups for user name specified and domain name specified as below

net user /domain Toms

In the above command, you can run net user command to get list of ad groups for user in domain.

The output of above command shows local group memberships and Global group memberships as below

Net user - Get list of active directory groups
Net user – Get list of active directory groups

Conclusion

I hope the above article on how to get list of ad groups for users is helpful to you.

You can read more articles about how to get list of users from ad group and export adgroup members to csv.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment