wiglack
asked on
Powershell script to make csv file with active directory users
My boss asked me to create a csv file with all the users in one container on AD. Since I'm still learning powershell and we need this right away, I'm asking you guys. I spent a few hours looking at example code, but I'd like something that works.
I need to collect the name and email address from the container Alpha in my domain. This needs to be outputed to a csv.
Not that complicated.
I need to collect the name and email address from the container Alpha in my domain. This needs to be outputed to a csv.
Not that complicated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use the following command...
get-contact -Filter 'name -like "*"' -OrganizationalUnit "OU=Alpha,DC=yourdomain,DC =com" | select Name, WindowsEmailAddress | export-csv "c:\contacts.csv"
Note: if you want to specify an OU it needs to be an OU not a container. If you want to remove the -Organizational parameter this will work but it will search for all contacts in your domain instead.
Thanks
Will.
get-contact -Filter 'name -like "*"' -OrganizationalUnit "OU=Alpha,DC=yourdomain,DC
Note: if you want to specify an OU it needs to be an OU not a container. If you want to remove the -Organizational parameter this will work but it will search for all contacts in your domain instead.
Thanks
Will.
ASKER
The contacts are in a container. Also, This cmdlet is not recgonized. Do I have to import a certain module to make that cmdlet work?
cn=emergencycontacts,dc=do main,dc=co m
cn=emergencycontacts,dc=do
Get-Contact is a Exchange Management shell (EMS) command, you need to run it from EMS or you need to add the exchange pssnapin to console before you run this command
The get-contact command will not work with a container. You need to use an OU for this. Why not just create a new OU called "emergencycontacts" and move all of the contacts from the container to the OU?
ASKER
I am also required to retrieve from another container full of contact objects. This command doesn't seem to work with contacts. How would I accomplish this?