Export Active Directory OU

zequestioner
zequestioner used Ask the Experts™
on
Hello Experts,

I am attempting to export contacts of an Active Directory OU into a csv file. I've found lots of links on how to do this, but I would prefer not to install any additional software. Here is the command I am using:

Get-ADUser -Filter * -SearchBase "ou=Ou,dc=contoso,dc=com" -Properties * | Export-Csv  "c:\somefile.csv"

Unfortunately, this command exports a csv with 0 entries.

I have tried removing the -Properties * but it still exports blank.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
MaheshArchitect
Distinguished Expert 2018

Commented:
You can try script in below post to export OU structure

http://blog.flaphead.com/2010/09/10/powershell-to-export-ad-ou-structure/
Top Expert 2014
Commented:
Contacts aren't users, so they wouldn't be returned by Get-ADUser.
You can try with Get-ADObject instead which will return the objects.

Author

Commented:
I would like to export the contents of the OU, which are objects with type 'Contact'.. I would like to export the name and email address of each contact in the OU.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
ah, gotcha. Let me try ADObject....

Author

Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for zequestioner's comment #a39886468

for the following reason:

Thanks!
Justin YeungSenior Systems Engineer

Commented:
here is the answer

Get-Adobject -filter {ObjectClass -eq "contact"} -searchbase "your ou path" -properties TargetAddress | select-object Name,TargetAddress | export-csv -path "yourpath"
Top Expert 2014

Commented:
@zequestioner - It appears that you selected the wrong comment as the solution...

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial