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

Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Microsoft Learning Snack - Green IT Through Virtualization Many organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. Order Your Fundamentals CD Today!Register today for your in-depth copy of one of three Fundamental CDs on the following topics – Exchange, SQL, and SharePoint. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Empower Your Processes with PowerShell 201Paul Robichaux delves deep into PowerShell how-tos in 3 informative lessons, each followed by live Q&A—all on your own computer! Register today! Microsoft Learning Snack - Green IT Through VirtualizationMany organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. New Release: Windows IT Pro Master CD13 years of content archives, fast answers with advanced search tools, and full access to WindowsITPro.com—order today!

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