Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

export AD user attributes powershell

Posted on 2014-10-20
15
Medium Priority
?
339 Views
Last Modified: 2014-11-03
I have a CSV file with usernames, the field heading is samaccountname

I would like to be able to read in this CSV and export AD attributes to another CSV
0
Comment
Question by:cmatchett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 16

Expert Comment

by:Enphyniti
ID: 40392996
Which AD attributes are you trying to export?
0
 

Author Comment

by:cmatchett
ID: 40393002
samaccountname, OfficePhone
0
 
LVL 29

Expert Comment

by:becraig
ID: 40393007
import-module ac*
import-csv c:\file.csv | %  {$user = $_.samaccountname; Get-Aduser | select (whaevet objects you need) | export-csv c:\results.csv -nti}

Open in new window


Since I am not sure what attributes you are after here is a list:

http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:cmatchett
ID: 40393030
becraig, i am getting


cmdlet Get-ADUser at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
0
 
LVL 29

Accepted Solution

by:
becraig earned 1000 total points
ID: 40393052
This should work:

import-module ac*
import-csv c:\file.csv | %  {$user = $_.samaccountname; Get-Aduser -identity $user -properties * | select  Officephone, samaccountname | export-csv c:\result.csv -nti

Open in new window

0
 
LVL 16

Assisted Solution

by:Joshua Grantom
Joshua Grantom earned 1000 total points
ID: 40393075
Missing an ending brace "}" it was set to overwrite the CSV with each user
$users = import-csv c:\file.csv | % {$user = $_.samaccountname; Get-Aduser -identity $user -properties * | select  SamAccountName,Officephone} | export-csv c:\result.csv -nti

Open in new window

0
 
LVL 29

Expert Comment

by:becraig
ID: 40393086
Thanks Joshua, did this on the phone, so no validation :~(
0
 

Author Comment

by:cmatchett
ID: 40393098
great work.  love experts exchange.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40393099
its alright. Also, is OfficePhone a valid attribute?

Usually there is just

telephoneNumber, mobile, otherTelephone, facsimileTelephoneNumber, homePhone, ipPhone, otherPager, otherMobile, otheripPhone, otherHomephone, and otherFacsimileTelephoneNumber...

Unless its an added attribute from exchange.

Also, if you could give credit to becraig, I just added a brace. At least give him most of it.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40393108
It is one of the extended properties, I think i provided a link in the first post that covers this.
0
 

Author Comment

by:cmatchett
ID: 40393142
sorry, what i meant to do was select multiple answers and select craigs as the best.

Yes officephone is the telephone attribute.

How can i undo my points scoring?  Can you go to a moderator and ask them to do it?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40393165
You can just file a request for attention, though I am ok to split the points.
0
 

Author Comment

by:cmatchett
ID: 40393190
request for attention filed
0
 

Author Closing Comment

by:cmatchett
ID: 40419897
great work
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question