Welcome to Scripting Forums Sign in | Join | Help
in Search

Import Back Into Active Directory

Last post 05-08-2007, 4:00 PM by jeppolito. 5 replies.
Sort Posts: Previous Next
  •  05-08-2007, 4:00 PM 766

    Import Back Into Active Directory

    Good afternoon all,

         I created a script (pasted below) which pulls the information from four tabs in Active Directory; General, Address, Telephones and, Organization. The script pulls the information for each field and then outputs it to an CSV file. We have over 3500 accounts so there is quite a bit of information and amongst other things we are planning to use the "Office" field under the General Tab to enter our cost centers. My question is this; is there a way to import the information from either an Excel spreadsheet or CSV file back into Active Directory?

                                                                                   Thank you in advance,

                                                                                   James

    PS sorry the script didn't paste well into the post.
     

    '==========================================================================

    ' ' VBScript Source File '

    ' NAME: AD_User_X.vbs

    ' ' AUTHOR: James Eppolito

    ' DATE : 3/28/2007 '

    ' COMMENT: Retrieves User Information from General, Address, Telephones, and Organization Tabs in Active Directory

    ' ' .CSV file format should be: ' ' SurName,GivenName,DisplayNname,Description,Office,Webpage,Street Address,PO Box,City,State,Zip Code,Country,Telephone,Pager,Mobile,Fax,IP Phone,Notes,Title,Department,Manager,Direct Reports,Home Directory ' '==========================================================================

    Option Explicit Dim rootDSE, oDomain, domainContainer, oFSO, oTS Const TF_PATH = "C:\users.csv" 'connect to the root of AD Set rootDSE=GetObject("LDAP://RootDSE") domainContainer = rootDSE.Get("defaultNamingContext") Set oDomain = GetObject("LDAP://" & domainContainer) Set oFSO = WScript.CreateObject("Scripting.FileSystemObject") Set oTS = oFSO.CreateTextFile(TF_PATH,True) 'start with the domain root and recurse through domain WorkWithObject(oDomain) 'completion notification WScript.Echo "User information has been written to: " & TF_PATH Sub WorkWithObject(oContainer) Dim oADObject For Each oADObject in oContainer On Error Resume Next Select Case oADObject.Class Case "user" 'oADObject represents a USER object; 'do something with it oTS.Write oADObject.Get("sn") oTS.Write "," oTS.Write oADObject.Get("givenName") oTS.Write "," oTS.Write oADObject.Get("displayname") oTS.Write "," oTS.Write oADObject.Get("description") oTS.Write "," oTS.Write oADObject.Get("physicalDeliveryOfficeName") oTS.Write "," oTS.Write oADObject.Get("wWWHomePage") oTS.Write "," oTS.Write oADObject.Get("streetAddress") oTS.Write "," oTS.Write oADObject.Get("postOfficeBox") oTS.Write "," oTS.Write oADObject.Get("l") oTS.Write "," oTS.Write oADObject.Get("st") oTS.Write "," oTS.Write oADObject.Get("postalCode") oTS.Write "," oTS.Write oADObject.Get("c") oTS.Write "," oTS.Write oADObject.Get("telephoneNumber") oTS.Write "," oTS.Write oADObject.Get("pager") oTS.Write "," oTS.Write oADObject.Get("mobile") oTS.Write "," oTS.Write oADObject.Get("facsimileTelephoneNumber") oTS.Write "," oTS.Write oADObject.Get("ipPhone") oTS.Write "," oTS.Write oADObject.Get("notes") oTS.Write "," oTS.Write oADObject.Get("title") oTS.Write "," oTS.Write oADObject.Get("department") oTS.Write "," oTS.Write oADObject.Get("manager") oTS.Write "," oTS.Write oADObject.Get("directreports") oTS.Write "," oTS.Write oADObject.Get("HomeDirectory") 'adds carriage return at the end of the line oTS.Write chr(13) & chr(10) Case "organizationalUnit" , "container" 'oADObject is an OU or container... 'go through its objects WorkWithObject(oADObject) End Select Next End Sub

  •  05-09-2007, 4:07 PM 778 in reply to 766

    Re: Import Back Into Active Directory

    Hi jeppolito,

    The first thing I would do is change your CSV generator script to include each account's CN attribute. Later on, you can use this attribute to update each account with new information. 

    To update the accounts, you can read in the CSV file as a Recordset object. See my sidebar "ADO Recordset Objects" (http://www.windowsitpro.com/Articles/ArticleID/93632/93632.html) for some resources that explain how to do this.

    HTH,

    Bill

  •  05-10-2007, 4:19 PM 789 in reply to 778

    Re: Import Back Into Active Directory

    I can easily add the CN attribute to the script but I'm not sure how this will help when it comes to getting the info back in.  Here's what I am trying to do: The Finance Department changed all the cost centers. The Planning Committee got the idea to use the "General-Office" field in AD to hold the cost center. I wrote the script, pulled all the info out, including the current cost centers currently populating the "Office" field. The Committee is now sending back spreadsheet with their changes to the cost centers. I need to get that information and only that information back into Active Directory. While I am at it I would also like to populate the Department field since they changed the names of those as well. I need it to overwrite the existing information in the Office field with the changes to the employee cost centers.  Does this make it a little clearer or worse? :)
  •  05-10-2007, 4:21 PM 790 in reply to 789

    Re: Import Back Into Active Directory

    I'm sorry I forgot to thank you for your response. I appreciate your help.

                                                          James
     

  •  05-11-2007, 9:19 AM 796 in reply to 789

    Re: Import Back Into Active Directory

    Hi jeppolito,

    I suspected that was what you wanted to do. The reason you need to include the CN attribute in your "output" script is so that you can easily reconnect to each account. In other words, the CN attribute uniquely identifies each AD account you want to modify.

    Next, you need to write a script that does something like this:

    1. Open the CSV file (see the resources I posted earlier)
    2. Connect to the user account (e.g., LDAP://CN=Joseph Bogus,OU=Foo,DC=wascorp,DC=com)
    3. Read the new value(s) from the CSV file
    4. Apply the new value(s) to the account

    HTH,

    Bill

  •  05-18-2007, 2:18 PM 821 in reply to 796

    Re: Import Back Into Active Directory

    Great! That helps tremendously. Thank you for posting.

                                                 James
     

View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Free Download –VS 2008 TrainingExperts Ken Getz & Robert Green plus labs, code, courseware Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Register for SolarWinds VM MonitorGet X-Ray Vision into Your ESX Servers with SolarWinds FREE VM Monitor GoGrid Offers FREE Trial for Windows Cloud ServersDeploy Windows Server 2003 and 2008 with free load balancing through GoGrid’s award winning web-based GUI – all in less than 5 minutes Order Your SQL Fundamentals CD Today! Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD. How healthy is your Exchange Server? Find out Now!Automatic Exchange Server Maintenance helps prevent disasters and improves performance. Download a FREE Exchange Server analysis tool. You've Deployed SharePoint...Now What?This one-day free online conference delivers the technical knowledge needed to kick MOSS up a notch. In one information-packed day, independent SharePoint experts will present practical, real-world information and provide take-away, ready-to-use solutions Ease Your Scripting Pains with the Flexibility of PowerShell!Paul Robichaux equips you with PowerShell basics in 3 introductory lessons, each followed by live Q&A—all on your own computer! Register today! What Would You Do If You Ran Microsoft?ITTV's 2008 inaugural video contest, "If I Ran Microsoft..." is your chance to tell it like it is. Be goofy or be serious, but don"t miss this chance to have fun, win prizes, and go viral in a major way. Maximize Your SharePoint InvestmentThis web seminar discusses how true bi-directional replication of SharePoint content from one server to another enables branch offices to maintain access to current SharePoint content. Rock Your Knowledge, and Compete with Friends and Colleagues!Are you the Web Application Performance Guru in your office? It's time to have fun! Download now to access the crossword puzzle. Challenge yourself and complete this fun activity!

 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing