Hi,
I have a problem and can not find the error.
This is a modefied script from Microsoft to create a user in Active Directory. I have just added some code to get the information from a excel document.
It worksfine if a add text or mixed content, but if I try to add just numbers it will return error -2147467259.
Ex.
postalCode = 100 00 (workes fine)
postalCode = 10000 (does not work)
Code:
--------------------------------------------------------
On error resume next
Dim arrADAtt(2,50)
Randomize
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("[file.xls]")
wscript.echo "1: " & err
'Set domain information
Set objOU = GetObject("LDAP://[OU DN])
wscript.echo "2: " & err
'Get all attributes from the first line.
intCol = 1
arr = 0
Do Until objExcel.Cells(1, intCol).Value = ""
Select Case objExcel.Cells(1, intCol).Value
Case "Result" strResultCol = intCol
Case "MailboxStore" strMailboxStoreCol = intCol
Case "Password" strPasswordCol = intCol
Case "cn" strcnCol = intCol
Case Else
arrADAtt(1,arr) = objExcel.Cells(1, intCol).Value
arrADAtt(2,arr) = intCol
arr = arr + 1
End Select
intCol = intCol + 1
Loop
wscript.echo "3: " & err
' Validate the gatherd attributes
If strResultCol = "" then Msgbox "Add a 'Result' column and try again" : funquit
If strPasswordCol = "" then Msgbox "Add a 'Password' column and try again" : funquit
If strcnCol = "" then Msgbox "Add a 'cn' column and try again" : funquit
If strMailboxStoreCol = "" then
answer = Msgbox("No mailboxstore is pressent in the datafile." & chr(13) & "No mailbox will be created. " & chr(13) & "Do you want to continue anyway?",305,"Warning")
If answer = 2 Then
funquit
End If
End If
wscript.echo "4: " & err
'Create user
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
Set Usr = objOU.Create("User","CN=" & UCase(objExcel.Cells(intRow,strcnCol).Value))
wscript.echo "5: " & err
arr = 0
Do Until arrADAtt(1,arr) = ""
usr.put arrADAtt(1,arr), objExcel.Cells(intRow,arrADAtt(2,arr)).Value
wscript.echo arrADAtt(1,arr) & " " & objExcel.Cells(intRow,arrADAtt(2,arr)).Value
arr = arr + 1
Loop
usr.setinfo
wscript.echo "6: " & err
strPW = "Scania." & int(1000 * Rnd())
objExcel.Cells(intRow,strPasswordCol).Value = strPW
usr.setpassword strPW
usr.setinfo
wscript.echo "7: " & err
If not strMailboxStoreCol = "" Then
'Create Mailbox
usr.CreateMailbox "Ldap://" & objExcel.Cells(intRow,strMailboxStoreCol).Value
usr.setinfo
wscript.echo "8: " & err
End If
' Done with this user, now we check status.
If err = 0 Then
objExcel.Cells(intRow,strResultCol).Value = "Done"
else
objExcel.Cells(intRow,strResultCol).Value = err
err = 0
End If
intRow = intRow + 1
Loop
objExcel.Save
objExcel.Quit
Function funquit
objExcel.Quit
wscript.Quit
End Function
----------------------------------------------------------
I have a problem and can not find the error.
This is a modefied script from Microsoft to create a user in Active Directory. I have just added some code to get the information from a excel document.
It worksfine if a add text or mixed content, but if I try to add just numbers it will return error -2147467259.
Ex.
postalCode = 100 00 (workes fine)
postalCode = 10000 (does not work)
Code:
--------------------------------------------------------
On error resume next
Dim arrADAtt(2,50)
Randomize
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("[file.xls]")
wscript.echo "1: " & err
'Set domain information
Set objOU = GetObject("LDAP://[OU DN])
wscript.echo "2: " & err
'Get all attributes from the first line.
intCol = 1
arr = 0
Do Until objExcel.Cells(1, intCol).Value = ""
Select Case objExcel.Cells(1, intCol).Value
Case "Result" strResultCol = intCol
Case "MailboxStore" strMailboxStoreCol = intCol
Case "Password" strPasswordCol = intCol
Case "cn" strcnCol = intCol
Case Else
arrADAtt(1,arr) = objExcel.Cells(1, intCol).Value
arrADAtt(2,arr) = intCol
arr = arr + 1
End Select
intCol = intCol + 1
Loop
wscript.echo "3: " & err
' Validate the gatherd attributes
If strResultCol = "" then Msgbox "Add a 'Result' column and try again" : funquit
If strPasswordCol = "" then Msgbox "Add a 'Password' column and try again" : funquit
If strcnCol = "" then Msgbox "Add a 'cn' column and try again" : funquit
If strMailboxStoreCol = "" then
answer = Msgbox("No mailboxstore is pressent in the datafile." & chr(13) & "No mailbox will be created. " & chr(13) & "Do you want to continue anyway?",305,"Warning")
If answer = 2 Then
funquit
End If
End If
wscript.echo "4: " & err
'Create user
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
Set Usr = objOU.Create("User","CN=" & UCase(objExcel.Cells(intRow,strcnCol).Value))
wscript.echo "5: " & err
arr = 0
Do Until arrADAtt(1,arr) = ""
usr.put arrADAtt(1,arr), objExcel.Cells(intRow,arrADAtt(2,arr)).Value
wscript.echo arrADAtt(1,arr) & " " & objExcel.Cells(intRow,arrADAtt(2,arr)).Value
arr = arr + 1
Loop
usr.setinfo
wscript.echo "6: " & err
strPW = "Scania." & int(1000 * Rnd())
objExcel.Cells(intRow,strPasswordCol).Value = strPW
usr.setpassword strPW
usr.setinfo
wscript.echo "7: " & err
If not strMailboxStoreCol = "" Then
'Create Mailbox
usr.CreateMailbox "Ldap://" & objExcel.Cells(intRow,strMailboxStoreCol).Value
usr.setinfo
wscript.echo "8: " & err
End If
' Done with this user, now we check status.
If err = 0 Then
objExcel.Cells(intRow,strResultCol).Value = "Done"
else
objExcel.Cells(intRow,strResultCol).Value = err
err = 0
End If
intRow = intRow + 1
Loop
objExcel.Save
objExcel.Quit
Function funquit
objExcel.Quit
wscript.Quit
End Function
----------------------------------------------------------