You can export users from Active Directory using PowerShell. The cmdlet below exports a complete list of my company’s users to a csv file.
Get-ADUser -Filter 'Company -like "Alpha*"' -Properties * | Select -Property EmailAddress,GivenName,Surname,DisplayName,Title,Department,Office,OfficePhone,MobilePhone,Fax,StreetAddress,City,State,PostalCode,Country | Export-CSV "C:\\ADusers.csv" -NoTypeInformation -Encoding UTF8
Get-ADUser cmdlet can either pull only one user from Active Directory, using –Identity parameter, or it can pull many users at once with –Filter or -LDAPFilter parameters. In this example, I use the filter to export all users who have the Company AD field starting from “Alpha”. Thanks to that, I will get only the users I want, without e.g. Healthmailboxes which would appear if I used “-Filter *”, instead.
The cmdlet creates ADusers.csv file on the C drive. If you want to use this file to import users into Office 365, you need to take 2 easy steps. First, you have to substitute the first row with the right headings from the file mentioned in step 4 above. Then, go to edit > replace and remove all quotation marks:
The cmdlet exports all AD properties used in Office 365 import file, so there is no need to spend any time copying and pasting columns like it was the case in previously described methods.