Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Do you want to export or import AD members (users) from Active Directory groups? This guide teaches you different methods to perform this task.

Option 1: Manage AD Group Members with PowerShell

As I already hinted in my introduction, you can use PowerShell to either export or import users from an Active Directory group. Talking about importing or exporting users, PowerShell can import from a CSV file or export to a CSV file.

However, when it comes to a text file, although you can import group members from a text file, it is limited. So, in the second subsection of this section, I will only show you how to export group members to a text file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

1. Export AD Group Members to a Text or CSV File With PowerShell

Follow the steps below to export or import group members to a text or CSV file:

#1 Best Overall
Sandisk 2TB Extreme Portable SSD, Up to 1050MB/s, USB-C, USB 3.2 Gen 2, IP65 Water and Dust Resistance, Updated Firmware, External Solid State Drive, SDSSDE61-2T00-G25
  • Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
  • Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
  • Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
  • Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
  • Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C
  1. Decide the user’s properties you want to export. To get a list of all the properties of the users in an AD group, use the command below:
To run the command, change “Remote Writers” to the name of the Active Group you want to export its members.
Get-ADGroupMember -Identity "Remote Writers"

The command returns the default properties of the members of the AD group. The AD group in my sample command has two members.

In this example, I’ll export the group members’ name, SamAccountName, and distinguishedName. Now, I will modify the previous command to return these values.

Get-ADGroupMember -Identity "Remote Writers" | Select-Object name, SamAccountName, distinguishedName

As expected, this command returns the properties I specified…

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
How To Export AD Group Members To A Text Or CSV File With PowerShell
  1. Decide whether you want to use the default properties of the headers or customize them. The next important step to exporting members of an AD group is to decide whether you want to change the table headers or use the default values.

If you decide to use the default values, retain the last command (as shown below); then proceed to step 3.

Get-ADGroupMember -Identity "Remote Writers" | Select-Object name, SamAccountName, distinguishedName

However, if you decide to customize the result headers, use a command similar to the one below:

Rank #2
Sale
Samsung T7 Portable SSD 1TB Titan Gray, USB 3.2 Gen 2, Up to 1,050MB/s | Reliable External Solid State Drive Storage for Gaming, Students, Professionals (MU-PC1T0T/AM)
  • MADE FOR THE MAKERS: Create; Explore; Store; The T7 Portable SSD delivers fast speeds and durable features to back up any endeavor; Build your video editing empire, file your photographs or back up your blogs all in an instant
  • SHARE IDEAS IN A FLASH: Don’t waste a second waiting and spend more time doing; The T7 is embedded with PCIe NVMe technology that brings fast read and write speeds up to 1,050/1,000 MB/s¹, making it almost twice as fast as the T5
  • ALWAYS MAKE THE SAVE: Compact design with massive capacity; With capacities up to 4TB, save exactly what you need to your drive – from large working files to game data and everything in between
  • ADAPTS TO EVERY NEED: Whether using a PC or mobile phone, count on the T7 for extensive compatibility²; It’s a true team player when it comes to heavy-duty application usage or file-saving
  • HI RESOLUTION VIDEO RECORDING: Record Ultra High Resolution (4K 60fs) videos directly onto the T7 Portable SSD with your favorite camera or mobile devices; Supports iPhone 15 Pro Res 4K at 60fps video and more³
Get-ADGroupMember -Identity "Remote Writers" | Select-Object @{Name="Full Name";Expression={$_.name}}, @{Name="UserName";Expression={$_.SamAccountName}}, distinguishedName
The modified column names uses the format – @{Name=”Column_name”;Expression={“object_property”}}. The Column_name is the name you want to display in the result. However, the object_property is the property name of the object – expressed with the pipeline variable – $_

Now the command returns more user-friendly column names!.

  1. Finally, export the AD group members to a CSV file or text file with the following commands, respectively.
Get-ADGroupMember -Identity "Remote Writers" | Select-Object @{Name="Full Name";Expression={$_.name}}, @{Name="UserName";Expression={$_.SamAccountName}}, distinguishedName | Export-CSV "C:\report\Remote_Writers_Members.CSV" -NoTypeInformation
The difference between this command and the last command is that, this command pipes the last command to the command – Export-CSV “C:\report\Remote_Writers_Members.CSV” -NoTypeInformation. I included the NoTypeInformation parameter of the Export-CSV command to remove typeinfomation from the CSV header.
Get-ADGroupMember -Identity "Remote Writers" | Select-Object @{Name="Full Name";Expression={$_.name}}, @{Name="UserName";Expression={$_.SamAccountName}}, distinguishedName | Out-File "C:\report\Remote_Writers_Members.txt" 

The two commands exports the AD group members to a CSV and text file respectively. In the screenshot below, I show the files explored and also the text file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
How To Export AD Group Members To A Text Or CSV File With PowerShell

2. Import Users to Active Directory Groups From CSV with PowerShell

In the last sub-section, I showed you how to export members of an AD group to text or CSV file with PowerShell. In this sub-section, you’ll learn how to perform the opposite task – import Active Directory users from a CSV file as AD group members.

To perform this task, follow the steps below:

  1. Create a CSV file with the SamAccountName of the AD users. The CSV file will have the SamAccountNames of the users you want to add to the AD group.

You can use the command below to export the SamAccountNames of the users. In this example, I am exporting all users in the domain to a CSV file called All_AD_users.csv.

In the command, I filtered out administrator and guest accounts. You can change the -SearchBase parameter value to the DN of another AD object you want to search for and export users from.
Get-ADUser -Filter "(Name -notlike 'guest') -and (Name -notlike 'administrator')" -SearchBase "DC=itechguides,DC=local" | Select-Object SamAccountName | Export-Csv C:\report\All_AD_users.csv -NoTypeInformation
  1. Import the users to the AD group using the command below. In this example, I am adding the AD users I exported in step 1 to the “Remote Writers” Active Directory group.

As shown in the screenshot below, the “Remote Writers” AD group does not have any members.

Rank #3
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
How To Import Users To Active Directory Groups From CSV With PowerShell

To import and add all AD users in my CSV file to the “Remote Writers” Active Directory group, I’ll run the command below:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Import-Csv C:\report\All_AD_users.csv | ForEach-Object {Add-ADGroupMember -Identity "Remote Writers" -Members $_.SamAccountName}

After I run the command, the “Remote Writers” Active Directory group has all the users in the CSV file as members.

Option 2: Manage AD Group Members with DSQuery

In this section, you’ll learn how to export AD group members to a text file. Unfortunately, if you use the “dsquery group” command to export users to a CSV file, it does not create headers.

So, if you want to use the command prompt to export Active Directory group members, I recommend you export to a text file. Based on all the aforementioned, to export the members of the “Remote Writers” Active Directory group to a text file, I’ll run the command below:

dsquery group -name "Remote Writers" | dsget group -members > C:\report\All_AD_users_.txt
The command uses the “dsquery group” command to return the DN of the AD group. Then, it pipes the result to the “dsget group” command, then uses its -members parameter to export the members. Finally, I the command export the users to a text file using the > redirection operator.

The result is a text file with the DN of all the users in the AD group.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model) | External Solid State Drive, Compatible with Laptops & Tablets, Up to 2M Drop Protection, USB 3.2 Gen 2, USB-C to USB-A Cable
  • Solid state performance with up to 800MB/s read speeds in a portable drive. (Based on internal testing; performance may be lower depending on host device, interface, usage conditions and other factors. 1MB=1,000,000 bytes.)
  • Back up your content and memories on a storage solution that fits seamlessly into your mobile lifestyle.
  • Take it with you on your adventures—up to two-meter drop protection means this durable drive can take a beating. (Based on internal testing.)
  • Secure it to your belt loop or backpack for extra peace of mind thanks to the tough rubber hook.
  • From Sandisk, a brand professional photographers trust to take on assignments.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

1. How do I export and import users from Active Directory groups?

To export users from an Active Directory group, run the Get-ADGroupMember PowerShell command. For example, the command below exports all members of the “Remote Writers” AD group:

Get-ADGroupMember -Identity “Remote Writers” | Select-Object SamAccountName | Export-CSV c:\reports\remote_writers.CSV -NoTypeInformation

Then, I can import the exported users as members of another AD group with the command below:

Import-Csv c:\reports\remote_writers.CSV | ForEach-Object {Add-ADGroupMember -Identity “Remote Writers” -Members $_.SamAccountName}

2. How do I export users from Active Directory?

There are so many objects you can export users from in AD. For example, you can export all users in the domain.

Alternatively, you can export users from a group or an OU. To export all users in your domain to a text file, run a command like the one below:

Get-ADUser -Filter “(Name -notlike ‘guest’) -and (Name -notlike ‘administrator’)” -SearchBase “DC=itechguides,DC=local” | Select-Object SamAccountName | Export-Csv C:\report\All_AD_users.csv -NoTypeInformation

Replace the value in the -SearchBase parameter with the DN of your domain. However, if you want to export all members of an OU, add the DN of the OU in the -SearchBase parameter.

Finally, to export AD users from a group, see question 1 above.

3. How do I export data from Active Directory to Excel?

To export data from Active Directory to Excel:

i) Run the relevant PowerShell command to retrieve the data you need from Active Directory
For example, to get the SamAccountName of all AD users in the domain (excluding guest and administrator), run the command below:

Get-ADUser -Filter “(Name -notlike ‘guest’) -and (Name -notlike ‘administrator’)” -SearchBase “DC=itechguides,DC=local” | Select-Object SamAccountName

ii) Then, to export the result to CSV file, pipe the result of the above command to the Export-Csv command. Here is a sample command.

Get-ADUser -Filter “(Name -notlike ‘guest’) -and (Name -notlike ‘administrator’)” -SearchBase “DC=itechguides,DC=local” | Select-Object SamAccountName | Export-Csv C:\report\All_AD_users.csv -NoTypeInformation

Before you run this command, change the -SearchBase to the DN of your domain.

4. How do I create an Active Directory user from a CSV file?

To create an Active Directory user from a CSV file, follow the steps below:

i) Use the Import-CSV command to fetch the users in the CSV file.
ii) Then, pipe the output of the Import-CSV command to a ForEach-Object command.
iii) Finally, within the ForEach-Object command, run the New-ADUser command and specify the entries from the CSV file.

Here is a sample command that creates new AD users from a CSV file that contains the users’ names and SamAccountNames.

Import-CSV [path to CSV file] | ForEach-Object {New-ADUser -Name $_.SamAccountName}

In this example, I assume that the user names of the users are in the SamAccountName column of the CSV file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
5. How do I export users from Windows?

The fastest way to export users from Windows is to run the Get-LocalUser PowerShell command. If you run this command without any parameters, it displays all Windows users on the local computer on the PowerShell console.

However, to export the users to a text file, pipe the result of the Get-LocalUser to Out-File.

Get-LocalUser | Out-File [path to text file]

Alternatively, to export all local Windows users to a CSV file, run the command below:

Get-LocalUser | Export-CSV [path to text file] –NoTypeInformation

Best Value
Sale
SANDISK 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model | External Solid State Drive, IP65 Water & Dust Resistant, Up to 3M Drop Protection, 256-bit AES Encryption, USB-C 3.2 Gen 2
  • NEARLY 2X FASTER THAN OUR PREVIOUS GENERATION(8) – move 1,000 high-res photos in under 60 seconds(6) with up to 2000MB/s transfer speeds(2).
  • IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.
  • POCKET-SIZED – fits easily in pockets and small bags.
  • SPACE TO OWN YOUR AI CONTENT – speed and capacity to download your high-res clips and photo edits.
  • 256-BIT AES ENCRYPTION(4) – helps keep private files secure with password protection.

Conclusion

One of the requested AD SysAdmins receives is producing user reports. Interestingly, one of the popular requests AD SysAdmins get is exporting members of an AD group.

The good news is that in this guide, I covered all the methods to complete this task.

Specifically, in the guide, I showed you how to perform this task with PowerShell. Not only that, but you also learned how to import Active Directory users to AD group members.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Then, the guide also covered how to export AD group members with Command Prompt.

I hope I made your day with this guide! If I did, click on “Yes” beside the “Was this page helpful” question below.

You may also express your thoughts and opinions by using the “Leave a Comment” form at the bottom of this page.

Finally, to keep improving your Active Directory skills, read more guides on our Active Directory Guides page.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.