Solved

export AD user attributes powershell

Posted on 2014-10-20
15
271 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
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 16

Expert Comment

by:Enphyniti
Comment Utility
Which AD attributes are you trying to export?
0
 

Author Comment

by:cmatchett
Comment Utility
samaccountname, OfficePhone
0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
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
 

Author Comment

by:cmatchett
Comment Utility
becraig, i am getting


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

Accepted Solution

by:
becraig earned 250 total points
Comment Utility
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 250 total points
Comment Utility
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 28

Expert Comment

by:becraig
Comment Utility
Thanks Joshua, did this on the phone, so no validation :~(
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:cmatchett
Comment Utility
great work.  love experts exchange.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
Comment Utility
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 28

Expert Comment

by:becraig
Comment Utility
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
Comment Utility
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 28

Expert Comment

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

Author Comment

by:cmatchett
Comment Utility
request for attention filed
0
 

Author Closing Comment

by:cmatchett
Comment Utility
great work
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now