Wednesday, 27 November 2013

Get specific properties with Get-ADUser and exporting to CSV

At some point we all need to obtain specific data of users to further analyze.
With this PS script you can get a specific data from a certain OU and export to csv.

Get-ADUser -Filter * -searchbase 'ou=your_ou_name,dc=yourdomain,dc=yourdomain' -Properties * | Select-Object Name, Pager | export-CSVresults.csv -NoTypeInformation -Encoding UTF8

With this script I can get the user name and the pager number on a CSV.
You can find what the objects you can use by using: Get-ADUser -Filter * -Properties *
Be aware it will display all users. So Ctrl+c in the middle of and search for your desired field. Or restrict your search base.
The file will appear on the path displayed on the powershell cmd when you open it.

No comments: