Rudy Rodarte . com


This article was written on 11 Jan 2018, and is filled under SQL Blogs, Windows.

Current post is tagged

, , ,

List all Active Directory Groups for users in an Active Directory group

The following PowerShell script finds all of the Active Directory group memberships for users in a target Active Directory Group. The PowerShell script is looking for 2 parameters:

  1. TARGET_AD_GROUP – The AD group in question
  2. $logfile – A text file destination, saved as a CSV

The script will first find all members of the TARGET_AD_GROUP. The script will then store the array of users in the variable $user. The script will then iterate over each of the users in the array. During each iteration, the script will find all groups that the current user is a member of. This resulting groups are stored in the array $groups. The script will then iterate over the groups and write out the current user and all of their group memberships to the logfile, one group at a time.

The results will look something like this:

AccountName UserName GroupName
asmith Adam Smith TARGET_AD_GROUP
asmith Adam Smith SECURE_AD_GROUP
asmith Adam Smith OTHER_AD_GROUP
bjones Brad Jones TARGET_AD_GROUP
bjones Brad Jones MANAGER_AD_GROUP
bjones Brad Jones CALENDAR_AD_GROUP
kcarter Kelly Carter TARGET_AD_GROUP
kcarter Kelly Carter SR_MANAGER_AD_GROUP
kcarter Kelly Carter MANAGER_AD_GROUP
wwoods Wilhem Woods DBA_AD_GROUP

You can then import the results into SQL Server, Excel, etc for pivoting and further analysis.


Rudy Rodarte is a SQL Server Database professional based in Austin, TX. Over his career, Rudy has worked with SSRS, SSIS, performance tuning troubleshooting. When away from Keyboard, Rudy goes to Spurs and Baylor Bear sporting events.

More Posts - Website - Twitter