PowerShell: Export Active Directory Group Members

by Robert Allen

In this guide, you will learn how to export AD group members to csv. I will show you how to get a list of groups and members with PowerShell and the AD Pro Toolkit. You can easily list group members with PowerShell but getting details for each user can be challenging. I’ll show you how to get a detailed group members report with the AD Pro Toolkit.

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
powershell module

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

check powershell ad module

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

Step 2: Use Get-ADGroup to find the group name

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 PowerShell command to list all Active Directory groups.

Get-ADGroup -filter * | sort name | select name
get-adgroup powershell command list groups

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 PowerShell command will list all members of my HR Full group.

Get-ADGroupMember -identity "HR Full"
get-adgroupmember powershell command

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
list only group members with powershell

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

Step 4: Export group members to CSV file with PowerShell

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

Pretty easy right?

Easily Export AD Group Members with AD Pro Toolkit

Exporting group members to CSV with PowerShell can become a time consuming and complex process. With the AD Pro Toolkit this task is very easy, you can create detailed group member reports with the click of the button.

The AD Pro Toolkit includes an Active Directory reporting tool with over 200 built-in reports. This is a huge time saver and eliminates the need to constantly making changes to complex PowerShell scripts.

Use the attribute selector to add or remove details to the group members export.

Group members reports include:

  • domain
  • group type
  • group scope
  • User Account status (enabled or disabled)
  • User lastLogonTimestamp
  • User email
  • User department, job title, city, state, company, office, phone, manager
  • You can customize the report to include the details you need
  • Send email reports and include the group members csv export

How to Export AD Group Members with AD Pro Toolkit

Step 1. Download the AD Pro Toolkit

Download AD Pro Toolkit

Step 2. Open Group Members Report

Click on “Group Members Reports” and select “Group Members”.

ad group members report

Step 3. Select groups or path

By default, the tool will run for all groups in your domain. To select specific groups or an OU click the “Browse” button. In this example, I have selected two groups that I want to export its members.

select ad group or ou

Step 4. Add or Remove Attributes

You can display additional details for each member of the group. For example, if I need to show the mail, whenCreated and whenChanged for each group member I can add those to the report. Click the “Columns” button if you want to add or remove attributes for the group members.

Step 4. Click “Run” to preview the export

This will display the groups and the group members for what you have selected. It creates a preview of what you want to export.

Step 5. Export Group Members

Click the “Export” button to export the group members to CSV. You can also choose to export the list to excel or PDF.

export group members to csv

Group members CSV example

Export AD Group Members in a single row

I’ve had several requests to add a report that shows the group and the group members in a single row. This report is now included in the toolkit. Below is an example, you can see the group name in one column and then in the next column it lists all of the group members in a single row.

To run this report click on “Group Member Reports” and then Group Members (Single line).

Nested Groups and Members

To get a list of nested groups and members click the “Nested Groups report. This will list all groups that are members of another group. If the parent group has members, you can expand it to see the list.

nested group and members report

Export only Security Group Members

If you only want to export the members of a specific group type such as security, follow these steps.

  1. Run the group members report for all groups in your domain
  2. Next, click on the groupType column and select Security.
get security groups

Now the tool will only display security groups and the group members. Click the export button to export the report.

list of security groups

The toolkit includes over 200 reports that can be customized, scheduled and export. Below are some additional group and group member reports included.

  • Nested groups
  • Nested groups tree view
  • Groups with no members
  • Large groups
  • Group member count
  • User group membership
  • All security groups
  • All distribution groups
  • Recently modified groups
  • Recently created groups
Download Free Trial

Schedule Automatic Group Member Reports

With the AD Pro Toolkit, you can schedule email reports of group members. This will email you a list of groups and members on a daily, weekly or monthly basis.

  1. Click on “Scheduler”.
  2. Click “Add”.
  3. Select “Reports” and give the task a name.
  4. Choose a schedule frequency and time.
  5. Select “Groups -> General” and then select “group members”.
  6. Select an OU or specific groups.
  7. For the Ouput options select “Email CSV” or “Save CSV”.

I hope this detailed guide helped you to export group members to csv. Exporting group members with PowerShell is pretty easy but can get complicated when trying to include additional user details. Next, you might also want to see our guide on how to export active directory users to csv.

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

  1. Leon

    So, it’s possible to output all users in a single group to a .csv file, but that means you have to know all the groupnames and change the input parameters for the powershell each time. Is it possible to output all users against all groups in a single domain to a .csv

    Groupname1 , , , etc
    Groupname2 , , , etc
    Groupname3

    I’m looking to check the users in each group and export them to excel as single lines for auditing and further analysis.

    Reply
    • Avatar photo
      Robert Allen

      This will export the groupName and members on one line.

      # Define the group name
      $groupName = “group1”

      # Retrieve the members of the specified group and join their SamAccountNames into a single string
      $members = (Get-ADGroupMember -Identity $groupName | Select-Object -ExpandProperty SamAccountName) -join “,”

      # Create a custom object with the group name and the members in one cell
      $groupDetails = [PSCustomObject]@{ GroupName = $groupName; GroupMembers = $members }

      # Export the custom object to a CSV file
      $groupDetails | Export-Csv -Path “C:\temp\groups.csv” -NoTypeInformation

      With our software it does this by default. Click “Group Reports” -> General -> All groups. Make sure the members column is added.

      Group members one line

      Reply
  2. Jo

    This article is so clear and easy to follow. Thank you.
    It works for some groups and for others I see an error “Get-ADGroupMember : Cannot find an object with identity: ‘Pwa xxx’ under: ‘DC=abc,DC=abc,DC=abc’ “.
    I see this has been answered in a previous comment but how do I know the name of the server or domain controller for a particular group?

    Reply
  3. SK

    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
      Robert Allen

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

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

      Reply
  4. Giuliano IT

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

    Reply
  5. Satya Singh

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

    Reply
  6. Aleksandar Dimitrov

    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
  7. Kumar

    Hai Robert Allen,

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

    Reply
  8. Adil

    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
  9. Jack

    Thanks Robert! Helped a lot

    Reply
    • Avatar photo
      Robert Allen

      No problem!

      Reply
  10. Alexandru Gheorghisoara

    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
  11. Invoke-Headache

    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
  12. Joe

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

    Reply
  13. A

    Thank you, this info was useful!

    Reply
  14. Danush Elango

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

    Reply
  15. Derek

    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
  16. vinay

    thank you so much. This blog helped me.

    Reply
  17. swati sueyawanshi

    Hi ,

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

    Reply
  18. Fady

    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
  19. Vaibhav

    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
  20. Becky

    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
  21. stiffneck

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

    Reply
  22. Daemon

    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
      Robert Allen

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

      Reply
      • Yonnas

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

        Reply
  23. Christopher Wayne

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

    Reply
  24. Maria

    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
  25. kuldip shilam

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

    Reply
    • Avatar photo
      Robert Allen

      Thanks Kuldip. Glad you found what you needed.

      Reply
  26. Linda

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

    Reply
  27. Vozdra Ba Hu Rami

    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
      Robert Allen

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

      Reply
  28. Stephanie

    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
  29. Riyaz Mirkar

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

    Reply
  30. Paul

    Just one word – AWESOME!!

    Reply
    • Avatar photo
      Robert Allen

      Thanks for the feedback Paul

      Reply
  31. Faiz

    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
      Robert Allen

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

      Reply
  32. P.G

    Very helpful tutorial. Thank you very much…

    Reply
  33. Jack

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

    Reply
    • Avatar photo
      Robert Allen

      Not sure, what exactly are you trying to accomplish?

      Reply
  34. Chi

    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
  35. Arun Kumar

    Hi Robert,

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

    Reply
    • Avatar photo
      Robert Allen

      No problem

      Reply
  36. Zo

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

    Reply
    • Avatar photo
      Robert Allen

      Zo, you are welcome.

      Reply
  37. Vince

    VERY informative.

    Thank you, Robert!

    Reply
  38. Simon

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

    Reply
  39. Abby

    Very Helpful. Thanks for sharing.

    Reply
  40. Rahul Kashyap

    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
  41. Dave Murdoch

    Clear and concise…thank you!

    Reply
    • Avatar photo
      Robert Allen

      No problem 🙂

      Reply
  42. Sachin

    Exactly What I needed. Thank You!

    Reply
    • Shasikumar Veerapan

      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
  43. Hugh

    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
  44. Raj

    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
      Robert Allen

      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
  45. Alan L

    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
      Robert Allen

      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
  46. Kiran Muthyala

    Thanks , this worked

    Reply
  47. Yuvaraj

    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
  48. Kristi

    This helped so much. Thank you!!!

    Reply
  49. Alberto Bigio

    Very Useful. Thanks

    Reply
  50. Thomas K

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

    Reply
  51. Paul

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

    Reply
  52. John B

    This was perfect. Thank you!

    Reply
  53. Dustin

    Amazing how simple you made this! thanks!!

    Reply
  54. Vicky

    Thanks for this 🙂

    Reply
    • Avatar photo
      Robert Allen

      No problem

      Reply
  55. Tommy

    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
  56. Jeevan

    Hi,

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

    Thanks

    Reply
  57. Papi

    Truly appreciate this, best explanation and clear instructions

    Reply
  58. Kumar

    thanks for good share , easy to understand and quick

    Reply
  59. Rod

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

    Reply
  60. Nathan

    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
      Robert Allen

      Here you go

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

      Reply
      • Geekgal

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

        Reply
      • tim's

        THANKS!! I was searching tooooo far away …

        Reply
  61. Bobby

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

    Reply
    • Avatar photo
      Robert Allen

      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
      • in need of help

        I LOVE YOU MAN

        Reply
      • Also in need of help

        I love you more.

        Reply
        • Avatar photo
          Robert Allen

          🙂

          Reply
  62. Guan

    This worked great!

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

    Reply
  63. Te'a Lutau

    Awesome Article!

    Reply
    • Avatar photo
      Robert Allen

      Thanks Latau

      Reply
  64. Senthil R (IBM India)

    really informative and useful commands for AD admins

    Reply
  65. Roger

    Awesome Thanks!

    Reply
    • Avatar photo
      Robert Allen

      No problem, I hope you find it useful.

      Reply
  66. Richard

    WOW this is well put together. Thanks.

    Reply
    • Avatar photo
      Robert Allen

      Richard,

      No problem.

      Reply
  67. me

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

    Reply
    • Avatar photo
      Robert Allen

      You’re Welcome!

      Reply
  68. Tamu Taylor

    Thank you!

    Reply
    • Avatar photo
      Robert Allen

      Tamu,

      You’re welcome

      Reply
  69. Edward Ramz

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

    Reply
    • Avatar photo
      Robert Allen

      No problem Edward.

      Reply
  70. Manny

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

    Reply
    • Avatar photo
      Robert Allen

      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
      • z

        Thanks big help

        Reply
        • Umanath

          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
      • Enzi

        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
          Robert Allen

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

          Reply
  71. Yulia

    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
      Robert Allen

      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
  72. Jay

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

    Reply
    • Avatar photo
      Robert Allen

      No problem Jay.

      Reply
  73. Chris

    Very helpful, thanks!

    Reply
    • Avatar photo
      Robert Allen

      No problem.

      Reply
    • Scott

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

      Reply
  74. Richard

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

    Reply
    • Avatar photo
      Robert Allen

      Hi Richard,

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

      Example

      Get-AdGroupMember -identity HR Full -Recursive

      Reply
      • Jayan Patel

        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
          Robert Allen

          I have a GUI tool for that https://activedirectorypro.com/reporting/

          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
        • Will Hughes

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

          Kind Regards

          Reply
          • Tako Zandink

            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”
            }
            }

      • Abhishek Dhar

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

        Reply
        • JohanS

          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
      • Diksha Deovansh

        How to export all groups from any particular member?

        Reply
        • Avatar photo
          Robert Allen

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

          Reply
      • Ramzi

        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
    • Joe

      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
      • Andrew Montgomerie

        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

Leave a Comment