Powershell get list of AD users / groups

Use the snippet below to get a list of all AD groups that a certain username is member of. Replace “[username]” with the correct username. Execute this command in a new Powershell window.

Get groups of user

Get-ADPrincipalGroupMembership [username] | select name

You should get the following response:

PS C:\Windows\system32> Get-ADPrincipalGroupMembership svc_myapp | select name

name
----
Domain Users
Service_accounts

Get users in a group

This command fetches all AD users in a group and returns their first and last name.

Get-ADGroupMember -Identity "[group-name-here]" | Get-ADUser -Property GivenName, SurName | Select-Object GivenName,SurName

It should return this response:

PS C:\Windows\system32> Get-ADGroupMember -Identity "Domain Admins" | Get-ADUser -Property GivenName, SurName | Select-Object GivenName,SurName

GivenName    SurName
---------    -------
John         Doe
Pete         Peterson

Good luck!

By Leendert de Borst

Freelance software architect with 10+ years of experience. Expert in translating complex technical problems into creative & simple solutions.

Leave a comment

Your email address will not be published. Required fields are marked *