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