Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 PowerShell
 Modify user attributes via CSV file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

meloao
Here To Stay

USA
114 Posts
Status: offline

Posted - 12/13/2011 :  8:11:07 PM  Show Profile  Reply with Quote
I would like to use a CSV file to update the telephone and title attributes in the User Obects in AD. Can anyone point me in the right direction?

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 12/14/2011 :  08:53:03 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
The first step is using Import-CSV to create objects you can pipe to some command to update the user object. That can be done a number of way depending on your situation. You could use the free AD cmdlets from Quest Software (Set-QADUser) or you could use the Microsoft AD Provider and the Set-ADUser cmdlet. This requires either a 2008 R2 DC or a DC running the AD Gateway service. As a last resort you could use old-fashioned ADSI. If it helps, I wrote an entire book on this topic: http://www.sapien.com/books/Managing-Active-Directory

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

JSCLMEDAVE
Administrator

USA
6116 Posts
Status: online

Posted - 12/14/2011 :  08:57:18 AM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
Save you a search...

Active Directory Management Gateway Service (Active Directory Web Service for Windows Server 2003 and Windows Server 2008)
http://www.microsoft.com/download/en/details.aspx?id=2852

Tim-

“This too shall pass"
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
3070 Posts
Status: online

Posted - 12/14/2011 :  3:27:07 PM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
Create a CSV file containing a unique identifier for the users an example could be SamAccountname, DN.
The add a column for the things you want to add, and preferably name the column headers the same as the AD attributes you want to populate.

Could be something like:

Import-Csv -path c:\myCSVFile.csv | %{set-qaduser -identity $_.Samaccountname -Mobile $_.Mobile -Title $_.Title}

The above is written without access to a Windows machine with powershell, so you have to check the parameter names.


Microsoft Powershell MVP

SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>

You can read my blog at www.xipher.dk
Go to Top of Page

meloao
Here To Stay

USA
114 Posts
Status: offline

Posted - 12/14/2011 :  7:02:36 PM  Show Profile  Reply with Quote
Thanks for the responses. Xenophane, for your script I will need a unique identifer ie SamAccoutname. Is there a way to export the SamAccount so I can add it to my CSV import file?
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 12/15/2011 :  08:33:55 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
It's too bad the cmdlet doesn't support pipeline binding. The csv file can use any heading you want. That becomes the property name that you'll use with Set-QADUser.

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

Isaac
Here To Stay

USA
208 Posts
Status: offline

Posted - 12/15/2011 :  12:13:03 PM  Show Profile  Reply with Quote
meloa,

do you mean getting all the users from AD? Try the following on your domain joined workstation:
dsquery user domainroot -limit 0 | dsget user -samid -ln -fn -dn

-samid = will give all the sam account name
-fn -ln = First and last names
-dn Distinguished Names
Go to Top of Page

meloao
Here To Stay

USA
114 Posts
Status: offline

Posted - 12/15/2011 :  12:22:42 PM  Show Profile  Reply with Quote
Issac - yes, but I want to export the samid to a csv file.
Go to Top of Page

meloao
Here To Stay

USA
114 Posts
Status: offline

Posted - 12/15/2011 :  1:52:55 PM  Show Profile  Reply with Quote
Ok, I was able to export to a file by addinn '> c:\samid.csv' at the end of the command.
Go to Top of Page

Wiseman82
Old Timer

United Kingdom
520 Posts
Status: offline

Posted - 12/15/2011 :  2:09:53 PM  Show Profile  Visit Wiseman82's Homepage  Reply with Quote
Some alternative options from my website that you might find useful:

http://www.wisesoft.co.uk/scripts/vbscript_update_user_attributes_from_csv.aspx
http://www.wisesoft.co.uk/software/bulkadusers/csv_update.aspx

PowerShell is good too though.

David Wiseman
MCSE (2000/2003), MCSA (2003), MCDBA, MCITP:Database Administrator
Go to Top of Page

meloao
Here To Stay

USA
114 Posts
Status: offline

Posted - 12/16/2011 :  09:17:24 AM  Show Profile  Reply with Quote
Your program, Wiseman82, worked great! Thank you so much!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000