How to get the Active Directory groups membership for user with Powershell

27 September,2019 by Jack Vamvas

Question: How can I get the Active Directory groups for a specific user using Powershell? I'm facing a problem where a user is getting a failed login to a SQL Server. This SQL Server has multiple Active Directory groups attached to it - but I don't have visibility to the members of the groups. 

I know I can use the Get-ADGroupMember powershell cmdlet , which would give the member list of a specified Active Directory group, but this would be time - consuming . 

Is there a Powershell based method to specify the domain user and return the list of active directory groups which they are a member of ?

Answer: There is powershell cmdlet to the rescue! Get-ADPrincipalGroupMembership

The Get-ADPrincipalGroupMembership cmdlet will return the group membership of the specified user , in the current domain  of the logon executing this cmdlet 

Example 1 : Return group membership of the specified user

Get-ADPrincipalGroupMembership 'MYID1' | select name

Example 2 : Return group membership of the specified user , but this time run the scan of another trusted domain . Note : using the -server switch 

Get-ADPrincipalGroupMembership 'MYID1' -server 'domanin2.net'| select name

 

Read more on Powershell and Active Directory 

How to search a different Active Directory Domain with Powershell ...

How to Export Active Directory Group Members with Powershell Get-ADGroupMember

How to install the Active Directory Module for Windows Powershell ...


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to get the Active Directory groups membership for user with Powershell


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer