AntiMalware Status

Export a list of members from an Active Directory group to a file

Here is a good command line in case you will have need to export members of from security group in Active Directory to a text file for whatever reason it may be on Microsoft Windows Server 2012 R2.

So here is the command line where I want to export all members of ENGINEERING group in Active Directory to a text file:

dsquery group -name “ENGINEERING” | dsget group -members > C:\memberlist.txt

Once the command completes, you should find a memberlist.txt file under C:\> 🙂

also can be used PowerShell:

Get-ADGroupMember -identity “ENGINEERING” | select name | Export-csv -path C:\Output\Groupmembers.csv -NoTypeInformation

5 Replies to “Export a list of members from an Active Directory group to a file”

  1. Hello,

    Is it also possible to extract the “Members of” of a specific user in a text file ?

    If a user is member of several ad ds folders, how could we export them all his memberships to a txt file?

    1. you mean all groups for a specific user ? yes, you can:
      Get-ADPrincipalGroupMembership john.doe | select name . — > gives you list of all Group membership for the specific user
      but also you can use for same = export members of group to txt or csv by using this command:
      Get-ADGroupMember -identity “ENGINEERING” | select name | Export-csv -path C:\Output\Groupmembers.csv -NoTypeInformation

      Hope it helps 🙂

      1. Thenks a lot for the reply cloud warrior.

        If I use : Get-ADPrincipalGroupMembership john.doe | select name Export-txt – path C:\… it will actually export all “Members of” in a text file ? And if so, will it be comma separated if I want to add all same “Members of” to another user?

        1. to output to TXT you need to use “Out-File” instead of “Export-Csv”
          Get-ADPrincipalGroupMembership john.doe | select name | Out-File -filepath C:\Output\Groups.txt
          the output looks like:
          name
          —-
          Domain Users
          APP-AWS DEVS
          APP-AWS ReadOnly
          APP-ServiceNow

          if you wanna copy group membership from one user to another you can use simple PowerShell script:
          example you want make Frank to be same as John …
          $SName = john.doe
          $DName = frank.doe

          $G = Get-ADUser -Identity $SName -Properties memberOf
          foreach($group in $G.memberof)
          {
          Add-ADGroupMember -Identity $group -Member $DName
          write-output $group
          }

          will copy group membership from John to Frank so Frank ends up with same groups …

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.