PowerShell: Export Active Directory Group Members

In this guide, you will learn how to use PowerShell to get AD group members and export them to a CSV file.

As an Administrator, you often need to get a list of groups and group members from Active Directory. This may be requested as part of a security Audit, permissions review, or export and import into other systems.

The problem is…

The built-in Active Directory Users and Computer console have no way to get all group members and export them.

To accomplish this we can use the PowerShell Get-ADGroupMember cmdlet. As an alternative to PowerShell, I’ll also show how to create a detailed Active Directory Group Membership Report with an easy-to-use GUI Tool.

Let’s get started.

How to Export Group Members to CSV with PowerShell

In this first example, I’ll show you how to export Active Directory group members using the Get-ADGroupMember PowerShell cmdlet.

Step 1: Load the Active Directory Module

To connect and query an AD group with PowerShell the Active Directory module needs to be loaded.

The Active Directory module can be installed with the following methods:

  • RSAT tools installed
  • Windows Server 2008 R2 and above with the AD DS or AD LDS server roles

You can run the following command to see if you have installed

Get-Module -ListAvailable

As you can see I don’t have the module installed.

If you already have the module loaded then jump to step 2, if not then follow these instructions.

To get the Active Directory module installed on my Windows 10 PC, I will need to download and install the RSAT tools.

With the RSAT tools installed, I run the Get-Module -ListAvailable command again

Now I have the module installed, let’s move on to step 2.

RELATED: Tutorial on how to install PowerShell modules

Step 2: Find AD Group

If you already know the name of the group, then skip to step 3.

If you’re not sure what the group name is, you can issue the following command to list all Active Directory groups.

Get-ADGroup -filter * | sort name | select name

Above, is a screenshot of some of the groups listed in my domain. I had an HR group but wasn’t sure of its complete name, I can see it’s HR full. I’ll use that group in step 3 to list out the members.

Step 3: Use Get-AdGroupMember to list group members

The following command will list all members of my HR Full group

Get-ADGroupMember -identity "HR Full"

You can see the above command provides more details on the group members than I need.

We can filter out the results and just get the member name with this command

Get-ADGroupMember -identity "HR Full" | select name

Perfect, now I just need to export this to CSV.

Related: How to export all Users from Active Directory

Step 4: Export group members to CSV file

The last step is to export the results to a CSV file

This is done by adding Export-csv to our above commands. The full command looks like this

Get-ADGroupMember -identity "HR Full" | select name | Export-csv -path c:\it\filename.csv -Notypeinformation

Get-ADGroupMember -identity “HR Full” | select name | Export-csv -path C:\it\filename.csv -NoTypeInformation

Now I have a CSV file of all the members from the HR Full Active Directory group.

Pretty easy right?

Method 2: Export AD Group Members Using the AD Pro Toolkit

In this example, I’ll use the AD Group Membership Report Tool from the AD Pro Toolkit to get AD group members. This tool makes it very easy to get AD group membership from a single group or all domain groups. See the steps below.

Step 1: Download the AD Group Membership GUI Tool

Click here to download a free trial

The tool is very easy to install, it can be installed on a workstation or server.

Step 2: Click on Group Report

In the list of tools select group report.

Step 3: Choose Paths and click run

You can choose to get group members from the entire domain, select an OU or group or search the domain for a specific group.

For this example, I’m going to select the entire domain.

Now click the run button to generate the report.

You will now have a list of all Active Directory groups and members.

The sAMAccountName column is the user or group account and the memberOf column is the group it is a member of.

Step 4: Export AD Group Members to CSV

To export the report, click the export button and select CSV, XLSX, or PDF.

The below screenshot is an example CSV export.

List only Security Group Members

With the GUI tool, you can easily filter on any of the columns. In this example, I’ll filter on the group type to list only security groups and members.

Click on the groupType column and select Security.

Now the tool will only display security groups and the group members.

Get Recursive AD Group Membership

By default, the GUI tool will get recursive group membership. This means if a group is a member of another group it will also list the nested group’s membership.

To see which groups are members of another group filter the objectclass column by group.

Below you can see the “Accounting_Local” group is a member of the “Accounting_printers group. The “HR_Local” group is a member of the “IT_Local” group.

Include Additional User Properties (attributes) in the Group Membership Report

To add additional user properties click the columns button and add or remove the attributes you need.

Now re-run the report and it will display the user properties that you selected.

Get AD Group Members from an Organizational Unit

In this last example, I’ll get group members from a group in an OU instead of the entire domain.

Select OU or group and click the browse button.

Next, select the OU. You can select multiple OUs or groups. I’ve selected my HR OU.

Run the report and it will list the groups and members from your selection, In my case, it will get all groups in the HR OU.

The Group Membership Report Tool is a huge time saver and makes it so easy to report and export group membership. Click here to download a free trial.

Related Content

Recommended Tool: Active Directory Pro Toolkit

The AD Pro Toolkit includes 14 tools in 1 to help simplify and automate Active Directory management.

Automate user creation, bulk update accounts, group management, logon reports, report NTFS permissions, cleanup, and secure AD, troubleshoot account lockouts, and much more.

In addition, the toolkit includes over 200 built-in reports.

Click here to download a free trial

128 thoughts on “PowerShell: Export Active Directory Group Members”

  1. I’m looking for a similar script to export to csv groups and members within groups:
    group1:member1….
    group1:member1…

    Reply
    • Avatar photo

      Hi Richard,

      Just add -Recursive at the end to include members of child groups

      Example

      Get-AdGroupMember -identity HR Full -Recursive

      Reply
      • Hi Robert,

        What if i have to get entire (All) groups in one excel?

        instead of a specific group, I need to have all my groups with their current users in it.

        Reply
        • Avatar photo

          I have a GUI tool for that https://activedirectorypro.com/ad-group-report/

          To do this in PowerShell you would use Get-ADGroup to get all groups and set them to a variable. Then use a for each loop to loop through each group and run get-adgroupmember on each group.

          Reply
        • Hi Jayan, Did you ever get this to work in Powershell?

          Kind Regards

          Reply
          • You could try something like this:

            $groups = get-adgroup -filter *

            foreach ($group in $groups) {
            $naam = $group.name
            $members = Get-ADGroupMember -identity $group
            write-host “Group: $naam”
            write-host “————————————-”
            foreach ($member in $members) {
            $memnaam = $member.samaccountname
            write-host “$memnaam”
            }
            }

      • Is it possible to add users from a CSV to a AD group

        Reply
        • Here’s how I got it to work:

          $date=get-Date -Format “yyyyMMdd”
          $groupList=Get-ADGroup -filter * | sort name | select name
          write-Output “””ADGroupName””,””ADUserSAMAccountName””” | Out-File .\ADGroupMembership-$date.csv
          foreach ($group in $groupList) {
          $memberList=Get-ADGroupMember -Identity $group.name | Select SamAccountName
          foreach ($member in $memberList) {
          write-Output “””$($group.Name)””,””$($member.SamAccountName)””” | Out-File .\ADGroupMembership-$date.csv -Append
          }
          }

          Reply
      • How to export all groups from any particular member?

        Reply
        • Avatar photo

          Get-ADPrincipalGroupMembership username | select name | export-csv -path c:\path

          Reply
      • Hi,

        I have problem with the bellow command:
        Get-ADGroupMember -identity “Bss_nbe” | select name
        it’s showing only domain users group members, but she is not listing contact members ( insite of the group we have users & contacts, this command show only users )

        Reply
    • I am trying to extract a list of users given a security group. I know that this is easily accomplished using:

      Get-AdGroupMember -identity “security group name” | select name | Export-csv -path C:\members.csv -NoTypeInformation

      But, what I am trying to do is perform this action given a .csv file of security groups. For example, I have 36 security groups that I would like to query for their respective members. Rather than run the above line 36 times in a row by manually inputing each security group, I would like to say: “Here, take this .csv file, iterate through it one by one and return the members of each group you see, then export all members sorted by each group when you reach the end of the file.

      Any ideas as to how to do this? I’ve tried using a foreach loop but I don’t think you can pass an array to the -identity parameter.

      Reply
      • Was the script ever confirmed for this? I have around 50 security groups and want to export all the data into 1 CSV file rather than editing the command 50 times per security group.

        Thanks

        Reply
  2. Very helpful, thanks!

    Reply
    • Avatar photo

      No problem.

      Reply
    • As many others have said, very helpful Robert, thank you!

      Reply
  3. Exactly what I needed. Thanks for the information in easily and quickly digestible format!

    Reply
    • Avatar photo

      No problem Jay.

      Reply
  4. Hello, Thank you for the post. But I get an error on Step 2: “get-adgroup : Unable to find a default server with Active Directory Web Services running.”

    Reply
    • Avatar photo

      Yulia,

      The Powershell Active Directory module uses AD Web services to manage and administer Active Directory. You will need to make sure your server is running AD web services. What version of server are you running?

      Reply
  5. What is the powershell command to export AD “Contacts” members of an AD group?

    Reply
    • Avatar photo

      Hi, Manny

      This command will list both contacts and users of an AD group.

      Get-ADGroup group-name -Properties member | select-object -ExpandProperty member

      Reply
      • Thanks big help

        Reply
        • Hi,
          I need to get the ad details of an user and then all the nested group details of all the AD groups which the user is part of. Can any one tell me how?

          Reply
      • Hi Robert,

        Such a time saver! When I try to export this to a csv it doesn’t work.
        I usually add | Export-csv -path filepath\filepath\file.csv

        Any ideas?

        Reply
        • Avatar photo

          Enzi, did you try it with a drive letter? | export-csv -path c:\filepath\file.csv

          Reply
  6. Thank you! amazing, thank you for your time and sharing the info thanks!!!

    Reply
    • Avatar photo

      No problem Edward.

      Reply
  7. Thank you!

    Reply
    • Avatar photo

      Tamu,

      You’re welcome

      Reply
  8. good article, clear and EZ to use,
    thank you.

    Reply
    • Avatar photo

      You’re Welcome!

      Reply
  9. WOW this is well put together. Thanks.

    Reply
    • Avatar photo

      Richard,

      No problem.

      Reply
  10. Awesome Thanks!

    Reply
    • Avatar photo

      No problem, I hope you find it useful.

      Reply
  11. really informative and useful commands for AD admins

    Reply
  12. Awesome Article!

    Reply
    • Avatar photo

      Thanks Latau

      Reply
  13. This worked great!

    Amy chance we can add last logon date? Other scripts I tried from the web did not work.

    Reply
  14. This is awesome! Do you know how to also get users email address?

    Reply
    • Avatar photo

      Here is an example that will list users name and email of a group

      Get-ADGroupMember -Identity HR-N-Drive-RW -Recursive | Get-ADUser -Properties Mail | Sel
      ect-Object Name, Mail

      Reply
      • I LOVE YOU MAN

        Reply
      • I love you more.

        Reply
        • Avatar photo

          🙂

          Reply
  15. Can you export samaccountname and name together? I tried it in various ways, but can only seem to do one or the other.

    Reply
    • Avatar photo

      Here you go

      Get-ADGroupMember -Identity HR-N-Drive-RW -Recursive | Get-ADUser | Select-Object Name,
      SamAccountName

      Reply
      • THANK YOU! I really needed the emails listed as well.

        Reply
      • THANKS!! I was searching tooooo far away …

        Reply
  16. I want the CSV to list the Group name in Column A and the member in Column B. How would I do that?

    Reply
  17. thanks for good share , easy to understand and quick

    Reply
  18. Truly appreciate this, best explanation and clear instructions

    Reply
  19. Hi,

    Kindly help me to get the user ids instead as there are 2000 profiel needs to be reset.

    Thanks

    Reply
  20. Hello Robert,

    How do i get the list of member from group A, group B, i.e group B is not a sub group of group A
    and i don’t want to right separate command like this Get-AdGroupMember -identity “Group A” | select name.

    I Tried Get-AdGroupMember -identity “Group A” “Group B” | select name and i got error :/

    Thanks for the help.

    Reply
  21. Thanks for this 🙂

    Reply
    • Avatar photo

      No problem

      Reply
  22. Amazing how simple you made this! thanks!!

    Reply
  23. This was perfect. Thank you!

    Reply
  24. Wow this is great. clear tutorial and easy to follow. Works exactly as I had hope. Thank you Robert!!!

    Reply
  25. Thanks for this, turned a slog of a job into a 5 min breeze! 🙂

    Reply
  26. Very Useful. Thanks

    Reply
  27. This helped so much. Thank you!!!

    Reply
  28. Thank you so much for this! As a beginner, I wanted a quick way of getting the list of users from a specific group. I searched it for weeks and finally found this post! . With these commands, lot of hours will be saved.

    Reply
  29. Thanks , this worked

    Reply
  30. very interesting/handy…
    I have a range of AD groups I want to list (eg all AD groups starting g_abcCouncil) how would I modify the filter command ?

    (I tried -filter g_abcCouncil* but got a parsing error, not supported)

    Reply
    • Avatar photo

      You want to list just the groups and sort them or the groups and members? This would get all groups and sort them get-adgroup -filter* | sort

      Reply
  31. It was really useful. Thank you. Is there a possibility to add First name and Last name in the output from the AD group

    Reply
    • Avatar photo

      Raj, my AD User Export Tool includes first and last name and several other user properties. It can be customized to export exactly what you need.

      Reply
  32. This is extremely handy especially for someone who is still learning Powershell. I wondered if this script could be configured to run in one domain and pull data from a group in another? You would have to be able to add ID and password from the other domain for it to work.

    Reply
  33. Exactly What I needed. Thank You!

    Reply
    • Good day ?, how to get 8000 members list from 1 AD group using cmdlet Get-AdGroupMember and export it to cvs file ?

      Thanks a lot and have a nice day ?

      Reply
  34. Clear and concise…thank you!

    Reply
    • Avatar photo

      No problem 🙂

      Reply
  35. This is Awesome.. Helped me a lot.

    I have two quick questions:
    1. How can I see Group name and Member name as output?
    2. How can I choose multiple groups?

    Thanks in advance.

    Reply
  36. Very Helpful. Thanks for sharing.

    Reply
  37. This is excellent! Simple to follow. That’s how I like it. Cheers.

    Reply
  38. VERY informative.

    Thank you, Robert!

    Reply
  39. It worked! Thanks for the help! Great page with great examples.

    Reply
    • Avatar photo

      Zo, you are welcome.

      Reply
    • Avatar photo

      No problem

      Reply
  40. Hi Robert,

    The Commands are working, But I need to export the members from Multiple Groups. Is there any commands for that ?

    Reply
  41. Hi Robert,
    Thank you for your post. How do I export group members from a specific domain. When I ran the Get-AdGroupMember command, it gets it from a different domain.

    Reply
  42. How would you filter down to a specific string in the Active Directory Domain Services Folder?

    Reply
    • Avatar photo

      Not sure, what exactly are you trying to accomplish?

      Reply
  43. Very helpful tutorial. Thank you very much…

    Reply
  44. Hi Robert,
    Thank you for your post. How do I export group members from a specific domain. When I ran the Get-AdGroupMember command, it gets it from a specific domain.

    Reply
    • Avatar photo

      You can use -server to specify the domain to export from.

      Reply
  45. Just one word – AWESOME!!

    Reply
    • Avatar photo

      Thanks for the feedback Paul

      Reply
  46. How do we find, when a user was added to a particular AD group and who added the user.

    Reply
  47. This is one of the best explanations that I could find – Thanks!

    Would you know how to deal with a group with a large amount of members? My results are “The size limit for this request was exceeded”

    Reply
  48. Short and sweet, thanks!

    However, FOR NOOBS LIEK ME, in Step 4, it’s confusing that after “Export-csv -path” you got new empty line and then “C:OutputGroupmembers.csv -NoTypeInformation” which doesn’t work.

    Obviously, it should be all together and have a backslash “\” to be able to export to the C-drive root IF it works by other policies. IMO would be better to point the output file to the “C:\temp\filename.csv” which is probably more accessible.

    Reply
    • Avatar photo

      Vozdra, it has been corrected. Thanks for pointing this out.

      Reply
  49. i need an export for names, email addresses, title, location and department…. is that possible?

    Reply
  50. Exactly what i am looking for Thank you Robert. I mostly get all the required stuff from activedirectorypro.com

    Reply
    • Avatar photo

      Thanks Kuldip. Glad you found what you needed.

      Reply
  51. Hi Robert, bit late to the party here. I am doing something similar but I wanted to be able to export only names that do not match part of a string to the CSV e.g names that do not match “admin*”. I can manipulate the CSV afterwards but would be great if I could do it as part of PS.

    Reply
  52. I hate to ask this because I should know. How do I get it to export the AD username instead of Last, First?

    Reply
  53. Hi could you point me in the right direction? Any help would be appreciated. At step 3 I’m running into the following error….

    Get-AdGroupMember : An unspecified error has occurred
    At line:1 char:1
    + Get-AdGroupMember -identity GROUP-TESTA
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: GROUP-TESTA:ADGroup) [Get-ADGroupMember], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember

    Reply
    • Avatar photo

      Does the group have members from another domain? This command only works if the group members are all from the same domain.

      Reply
      • How can I get properties like samaccountname, mail, etc for a group that has members from more than one domain?

        Reply
  54. How do we find the AD groups assigned to a Role?

    Reply
  55. Hi Robert, how would I get a listing of all members in an AD group that has members from 2 different domains (universal group). Is this possible? Thanks.

    Reply
  56. Thanks ,Its very useful for audit purpose, I have created around 24 .CSV file. How do I can add all in one excel in different tabs in sing excel.

    Thanks again
    Vaibhav Joshi

    Reply
  57. Hi Robert, thank you for sharing all these helpful commands and PS-Scripts.

    I am trying to create a script that will export all users with their manager name to a csv file. (i got this part done already), I used: get-aduser -Filter * -Properties Manager | Select-Object Name,sAMAccountName,Manager | export-csv C:\temp\UsersManagersExample.csv -notypeinformation.

    But also that shows all the membership groups for each user. I am not sure what is the best way to achieve this. Can you help? I am quite sure that there is a way to get this done using powershell.

    So I am trying to get a list of all managers and their reporties plus the membership assigned to each user.

    Thank you in advance!
    Best Regards,

    Fady

    Reply
  58. Hi ,

    I have 120 dl names in one CSV file. How I can get the first member of that all dl using script

    Reply
  59. thank you so much. This blog helped me.

    Reply
  60. Hi
    How do I get groups within a nested group please? So I have a parent group, then within that, I have nested groups. I wanted those nested groups (not users)

    Thanks

    Reply
  61. Hi
    How to export the owners name for a list of service accounts from Powershell ?

    Reply
  62. Thank you, this info was useful!

    Reply
  63. Hi Robert,
    this is great – any idea how to omit specific emails from results?

    Reply
  64. This is very clean and retrieves the information I need for a compliance report. However, I have been asked to transpose data such that the export is formatted such that each group becomes a column header, and the columns contains all members of the “header” group. Any help is greatly appreciated.

    Thank you!

    Reply
  65. Hi,
    You did a great job!

    I would like to add few details at Step2 if you don’t see the groups, if the AD has azure information protection.
    First you will need to check the name of the group in AD then use the following command in PowerShell:
    Get-ADGroupMember -identity “Group_Name” | select name

    All the best,
    Alex Gheorghisoara

    Reply
  66. Thanks Robert! Helped a lot

    Reply
    • Avatar photo

      No problem!

      Reply
  67. Can i get the full script which i can run in azure DevOps pipeline and get the details of all AD groups as well as group users.

    Reply
  68. Hai Robert Allen,

    How to get user groups names using logon name and password with power shell script and LDAP bind connection.

    Reply
  69. Hi Robert Allen,
    can you help please!
    I need a info with all local administrators on servers and computers ,but excluded Domain Admins Group

    Reply
  70. I want the following command to search the entire directory
    Get-ADGroupMember -identity “TEST_GROUP_NAME”

    Reply
  71. Hi,
    Is it possible to to retrieve a list of deleted users for a particular group?
    Thanks

    Reply
  72. We have multiple domain controllers, how can we get the output for a group in a
    different DC

    Get-ADGroupMember : Cannot find an object with identity: ‘DC2XXYY-ABCD’ under:
    ‘DC=dc2,DC=int,DC=us’.

    the same command works for groups in dc1

    Reply
    • Avatar photo

      To get group members from a specific domain controller use the -server parameter.

      Get-ADGroupMember -server dc2 -identity “HR Full”

      Reply

Leave a Reply to Kristi Cancel reply