Advertisement
It will happen again and again. Your customers or colleagues will ask you to export specific user data from Active Directory. The easiest way to do this is with the command “Get-ADUser”. Simply select the specific objects like DisplayName, Username,.. and export the result to a CSV file with the specified encoding and delimiter.
Import-Module ActiveDirectory
Get-ADUser -Filter * -properties * | select-object DisplayName,sAMAccountName,telephoneNumber,mobile,mail,Department,Description | export-csv c:\temp\UserDataExport.csv -Encoding utf8 -notype -Delimiter ";"
Most of the time not all users are necessary, so there are more options to filter of course.
Advertisement
Export only specific Organizational Unit (OU)
You can filter for an Organizational Unit by using the -SearchBase option:
Import-Module ActiveDirectory
Get-ADUser -SearchBase "OU=Users,OU=<SubUnit>,OU=<MainUnit>,DC=<domainName>,DC=com" -Filter * -properties * | select-object DisplayName,sAMAccountName,telephoneNumber,mobile,mail,Department,Description | export-csv c:\temp\UserDataExport.csv -Encoding utf8 -notype -Delimiter ";"
Export group members
Another useful command is to export the members of a security group:
Import-Module ActiveDirectory
Get-ADGroupMember -Identity '<GroupName>' | Select-Object name, samaccountname | export-csv c:\temp\exportGroupMembers.csv -Encoding utf8 -NoType -Delimiter ";"
Advertisement