Get AD Group Memberships of all Users in a OU

Posted on 2014-08-27
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

    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

    Very nice, Thank you!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now