How to Export Active Directory Attributes Using Powershell
You can write a powershell script to export active directory attributes to a .txt or .csv file as required
First of All, you will need to install the AD Powershell Module in the server where you will be running the script from
To Install the AD powershell Module,
On a windows Server 2012, Open Powershell Console in an Elavated mode (with admin rights)
Then run the following command
PS C:\> import-module servermanager
PS C:\> Add-WindowsFeature -Name “RSAT-AD-PowerShell” –IncludeAllSubFeature
Now Create a new folder in a location, IE – C:\ADAttributeExporter – note that when you run the powershell script this will be the folder the exported file will be stored under.
Create a notepad or Notepad++ file and copy the required command (this depends on the attributes you want to export from AD)
In my case I want to only get User Information, thus filter out and only export these attributes (Enabled users, GivenName,Surname,Company,Title,Department,EmailAddress,TelephoneNumber,Fax,StreetAddress,City,State,PostalCode,Country,Manager) – note here that all the attributes are typed in one word, usually you cant put spaces between attributes
So in my case, the script is this,
Import-Module ActiveDirectory
Get-ADUser -Filter * -Properties * | Select Enabled,GivenName,Surname,Company,Title,Department,EmailAddress,TelephoneNumber,Fax,StreetAddress,City,State,PostalCode,Country,Manager | Export-Csv ‘C:\ADAttributeExporter\ADAttributeExport.Csv’ –NoTypeInformation
So it looks like this
Now save the file and change the name of file extension to .ps1
Now open powershell again and change directory to where you saved the above file,
I don’t need to explain how to move in to different directory to run poweshell commands,
Once you are in the folder, type the first couple of letters of your exported csv file and tab, this will select the .ps1 file in powershell, now just press entre and you are all done.
Now go back to that folder to check the exported file.






Leave a Reply