Active Directory Import

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
jeppolit
Posts: 1
Joined: Tue May 08, 2007 6:59 am

Active Directory Import

Post by jeppolit » Tue May 08, 2007 7:55 am

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. '=========================================================================='' 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 ExplicitDim rootDSE, oDomain, domainContainer, oFSO, oTSConst TF_PATH = "C:users.csv"'connect to the root of ADSet 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 domainWorkWithObject(oDomain)'completion notificationWScript.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 NextEnd Sub

User avatar
ruaand79
Posts: 12
Joined: Thu May 03, 2007 11:28 pm

Active Directory Import

Post by ruaand79 » Tue May 08, 2007 7:01 pm

You can try CSVDE that comes with Windows 2003 server to import data into AD.

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

Active Directory Import

Post by donj » Thu May 10, 2007 9:18 am

So, if you look at the code generated by the ADSI Scriptomatic (download from Microsoft), do you have any questions about how to proceed?

Generally:
Set user = GetObject("LDAP path to user object")
user.Put "GeneralOffice","New Value"
user.SetInfo

(or whatever the attribute name is really called - I don't have my ADSI Scripting: TFM book handy to look it up)

Locked