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

Re: ADSI Script to populate numerous attributes by Slim

Slim
Fri Dec 15 22:36:48 CST 2006


<mcmullin10@comcast.net> wrote in message
news:1166240597.045765.12740@16g2000cwy.googlegroups.com...
>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??
>



you need to give the Distinguished Name of the Manager


to get Distinguished Name



function getUserDN(userName)
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 10
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
objCommand.CommandText = _
"SELECT distinguishedName FROM 'LDAP://dc=thatsit,dc=local' WHERE
objectCategory='user' " & _
"AND sAMAccountName='"& userName &"'"
Set objRecordSet = objCommand.Execute
dim ans
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
ans = objRecordSet.Fields("distinguishedName").Value
objRecordSet.MoveNext
Loop
getUserDN = ans
end function







>
> 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
>