Export Active Directory OU

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.
LVL 1
zequestionerAsked:
Who is Participating?
 
footechConnect With a Mentor 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.
0
 
MaheshArchitectCommented:
You can try script in below post to export OU structure

http://blog.flaphead.com/2010/09/10/powershell-to-export-ad-ou-structure/
0
 
zequestionerAuthor 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.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
zequestionerAuthor Commented:
ah, gotcha. Let me try ADObject....
0
 
zequestionerAuthor 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!
0
 
Justin YeungSenior Systems EngineerCommented:
here is the answer

Get-Adobject -filter {ObjectClass -eq "contact"} -searchbase "your ou path" -properties TargetAddress | select-object Name,TargetAddress | export-csv -path "yourpath"
0
 
footechCommented:
@zequestioner - It appears that you selected the wrong comment as the solution...
0
 
zequestionerAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.