I want to modify some attributes in ADUC, more specifically for all
user accounts in the domain I want to pull in 4 columns from a csv or
xls file that populates the corresponding attributes of each user
account in Organization: fields = Deparment and Company
For example, if I have the csv file containing column 1 containing
username, column 2 containing Department data and column 3 containing
Company data and number 4 = "Manager" I have this script which gives
me all 3, but can't seem to get the Manager attribute to populate.. can
any offer any suggestions??
Const ADS_SCOPE_SUBTREE = 2
Set rootDSE = GetObject("LDAP://rootDSE")
sADSPath = rootDSE.Get("defaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users.xls")
objExcel.Visible = False
i = 1
Do Until objExcel.Cells(i, 1).Value = ""
strName = objExcel.Cells(i, 1)
strDept = objExcel.Cells(i, 2)
strCO = objExcel.Cells(i, 3)
objCommand.CommandText = _
"SELECT aDSPath FROM 'LDAP://" & sADSPath & "' " & "WHERE
objectCategory='user' " & _
"AND samAccountName='" & strName & "'"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 1 Then
strUser = objRecordSet.Fields("aDSPath").Value
Set objUser = GetObject(strUser)
objUser.Put "Department", strDept
objUser.Put "Company", strCO
objUser.SetInfo
Else
objExcel.Cells(i, 4) = "Not found"
End If
i = i + 1
objRecordSet.Close
Loop
objConnection.Close
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
Set objUser=Nothing
Set objExcel=Nothing
Set objWorkbook=Nothing
Set objRecordSet=Nothing
Set objCommandText=Nothing
Set objConnection=Nothing