Sie sind auf Seite 1von 2

OPTION Explicit

On Error Resume Next

Const ADS_PROPERTY_UPDATE = 2

DIM username, ou, n, arrStr


DIM strFullName, strAddress1, strAddress2
DIM strCity, strState, strZIP, strPhone, strEmail
DIM strAreaCode, strExchange, strDID, strTelephone
DIM objUser, objFSO, objCSVFile, objConnection, objCommand
Dim objShell, objFile, objNetwork

Set objShell = CreateObject("WScript.Shell")


Set objFSO = CreateObject("Scripting.FileSystemObject")

'Read CSV
Set objCSVFile = objFSO.OpenTextFile("UserInfo.csv",1)

Set objConnection = CreateObject("ADODB.Connection")


Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

'set counter value


n = 0

Do while NOT objCSVFile.AtEndOfStream

arrStr = split(objCSVFile.ReadLine,",")

strFullName = arrstr(n) & " " & arrstr(n+1)


strAddress1 = arrstr(n+2)
strAddress2 = arrstr(n+3)
strCity = arrstr(n+4)
strState = arrstr(n+5)
strZip = arrstr(n+6)
strPhone = arrstr(n+7)
'build a traditional phone number
strAreaCode = mid(strPhone,1,3)
strExchange = mid(strPhone,4,3)
strDID = mid(strPhone,7,4)
strTelephone = "(" & strAreaCode & ") " & strExchange & "-" & _
strDID
strEmail = arrstr(n+8)

' Call function to find OU from computer name


ou = getOUByUserName(strFullName)

if ou = "" then
wscript.echo strFullName
else
i = 0
Set objUser = GetObject("LDAP://cn=" & strFullName & "," & _
ou & "")

do while i < 1
If err.number <> 0 then
wscript.echo "Error: " & strFullName & " " & _
err.number
else
'Set the attribute values
objUser.Put "streetAddress", strAddress1 & vbCrLf & _
strAddress2
objUser.Put "l", strCity
objUser.Put "st", strState
objUser.Put "postalCode", strZip
objUser.Put "telephoneNumber", strTelephone
objUser.Put "mail", strEmail
'Set the user info
objUser.SetInfo
end if
i = i + 1
loop

end if

n = 0

Loop
objCSVFile.Close

function getOUByUserName(byval UserName)

DIM namingContext, ldapFilter, ou


DIM cn, cmd, rs
DIM objRootDSE

set objRootDSE = getobject("LDAP://RootDSE")


namingContext = objRootDSE.Get("defaultNamingContext")
set objRootDSE = nothing

ldapFilter = "<LDAP://" & namingContext & _


">;(&(objectCategory=User)(name=" & userName & "))" & _
";distinguishedName;subtree"

set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")

cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn
cmd.commandtext = ldapFilter

set rs = cmd.execute

if rs.eof <> true and rs.bof <> true then


ou = rs(0)
ou = mid(ou,instr(ou,",")+1,len(ou)-instr(ou,","))
getOUByuserName = ou

end if

rs.close
cn.close

end function

Das könnte Ihnen auch gefallen