Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Get AD Group Memberships of all Users in a OU

Posted on 2014-08-27
Medium Priority
Last Modified: 2014-08-28
I am doing my first steps in powershell and am already a bit stuck on an issue,
I am trying to get a list of all Users in a OU and there Group memberships to a file that I can Import in to excel

My initial try was:

PS C:\> Get-ADUser -LDAPFilter "(name=*)" -SearchScope Subtree -SearchBase "OU=users,OU=Paris,DC=Contoso,DC=North,DC=Com" | Get-ADPrincipalGroupMembership | select name | Out-File -FilePath C:\Temp\ADExtract.txt

And I do get a List of all Group Memberships for each user but unfortunately the output is unusable since I cannot tell which user account the group membership belongs to.

Any help much appreciated
Question by:David
LVL 40

Accepted Solution

Subsun earned 2000 total points
ID: 40287862
Get-ADUser -LDAPFilter "(name=*)" -SearchScope Subtree `
 -SearchBase "OU=users,OU=Paris,DC=Contoso,DC=North,DC=Com" | %{
  $user = $_
   $user | Get-ADPrincipalGroupMembership | 
 Select @{N="User";E={$user.sAMAccountName}},@{N="Group";E={$_.Name}}
}| Select User,Group | Export-Csv C:\report.csv -nti

Open in new window


Author Closing Comment

ID: 40289766
Very nice, Thank you!

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Screencast - Getting to Know the Pipeline

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question