We can export users from Active Directory using PowerShell in single line of code.
Using poweshell is when we want to do automaion or via program we want to have a list of all AD users.
The command(cmdlet) shown next exports a complete list of Active Directory users to a csv file.
Get-ADUser -Filter 'Company -like "ABC*"' -Properties * | Select -Property EmailAddress,GivenName,Surname,DisplayName,Title,Department,Office,OfficePhone,MobilePhone,Fax,StreetAddress,City,State,PostalCode,Country | Export-CSV "C:\\ExportedADUsers.csv" -NoTypeInformation -Encoding UTF8
In above code, Get-ADUser cmdlet gets the number of users at once with –Filter or -LDAPFilter parameters. Here, the filter exports all the users who have the Company AD field starting from “ABC”. The above command will create a csv file at C: drive named C:\\ExportedADUsers.csv.