Help! (Long Post, but I'm desperate)
Hello everyone, first time poster and a first time "VB" user. I guess you could call me that. Let me preface my problem with a few things:
- I'm an IT worker, but by no means a programmer
- I've taken precisely one class in programming, and it was Java (last year)
- I'm using Notepad to create VBScripts to help our summer at a K-12 School district easier by making a self-service password reset script.
So here I go... I've been working all week on a Password Reset script, and I can't do it anymore. I've googled the world over, and I've managed to throw together a script that will almost do the trick.
However, this script is just part of my main script that will reset the passwords. This segment--I segmented my script into parts, to ensure each part was working properly (and this is the part that doesn't work) is supposed to retrieve a name,via InputBox, and match/resolve it with the user name in the active directory via LDAP, and then continue with the rest of the script (not pictured) to reset the password. I don't know what else to explain, so I'm just throwing the script there, and praying that a kind soul can correct my error(s). I always assume any error I make is a small oversight.
A few more notes about our network...
- We have a domain called STUDENT, where our student accounts are stored. STUDENT is a part of our domain, BRIDGECITYISD.com.
- Hanz Magoo (username scheme: hanz.magoo) is a theoretical user, and more or less an inside joke with my co-workers. He is the account in question that we would like to reset.
- I've had so many errors, but I've changed so much that previous errors don't show up, but the error that occurs with this exact version is on Line 33, "An Operations Error Occurred." Code: 80072020.
So without further ado, here she is:
call_ldap_name.vbs
-------------------------
vb Code:
Option Explicit
Dim objOU, objUser, objUserName, objRootDSE
Dim strContainer, strDNSDomain, strPassword, strLastName, strFirstName, strMyName, strLDAPName
Dim intCounter, intAccValue, intPwdValue, intpwdLastSet, intAnswer
strContainer = "OU=High School,DC=Student,DC=bridgecityisd,DC=com"
strPassword = "l33tsauce@"
intAccValue = 544
intPwdValue = 0
strLastName = ""
strFirstName = ""
strLDAPName = ""
strFirstName = InputBox ("Enter your First Name:")
strLastName = InputBox ("Enter your Last Name:")
strMyName = strFirstName & "." & strLastName
WScript.echo "UserName is: " & strMyName
WScript.echo "Script Will Now Attempt to Resolve Name to LDAP"
WScript.sleep 1500
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = strContainer & strDNSDomain
set objOU = GetObject("LDAP://ou=High School,dc=student,dc=bridgecityisd,dc=com")
'Wscript.echo "objOU is: " & objOU
strLDAPName = strLDAPName & strLastName &", "& strFirstName
Wscript.echo "Unresolved LDAP Name is: " & strLDAPName
Set objUser = GetObject("LDAP://cn=strLDAPName,ou=strContainer")
WScript.echo "Resolved LDAP UserName is: " & objUser.CN
WScript.quit
------------------
Re: Help! (Long Post, but I'm desperate)
Starting with Option Explicit as line 1, line 33 is WScript.echo "Resolved LDAP UserName is: " & objUser.CN. Evidently the line above it isn't setting it to anything usable.
Re: Help! (Long Post, but I'm desperate)
That's one thing I was wondering about, can I call other objects in getObject?
Re: Help! (Long Post, but I'm desperate)
Quote:
Originally Posted by Al42
Starting with Option Explicit as line 1, line 33 is WScript.echo "Resolved LDAP UserName is: " & objUser.CN. Evidently the line above it isn't setting it to anything usable.
*bumping* I appreciate the insight on where to locate the cause of the problem in my script, but I've tinkered with it and I'm unable to find anything to fix it. Any suggestions?
Re: Help! (Long Post, but I'm desperate)
Quote:
Originally Posted by star_topology
*bumping* I appreciate the insight on where to locate the cause of the problem in my script, but I've tinkered with it and I'm unable to find anything to fix it. Any suggestions?
What "tinkering" have you done?
Re: Help! (Long Post, but I'm desperate)
Well, now I can get the script to run, but I'm getting a different error; the "no object found on the server" on line 34. As you can see, I added another string, DContainer.
vb Code:
Option Explicit
Dim objOU, objUser, objUserName, objRootDSE
Dim strContainer, strDNSDomain, strPassword, strLastName, strFirstName, strMyName, strLDAPName, strDContainer
Dim intCounter, intAccValue, intPwdValue, intpwdLastSet, intAnswer
'5
strContainer = "OU=High School,"
strDContainer = ", dc=student, dc=bridgecityisd, dc=com"
strPassword = "l33tsauce@"
intAccValue = 544
intPwdValue = 0
strLastName = ""
strFirstName = ""
strLDAPName = ""
'14
strFirstName = InputBox ("Enter your First Name:")
strLastName = InputBox ("Enter your Last Name:")
strMyName = strFirstName & "." & strLastName
WScript.echo "UserName is: " & strMyName
'19
WScript.echo "Script Will Now Attempt to Resolve Name to LDAP"
'21
WScript.sleep 1500
'23
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = strContainer & strDNSDomain
set objOU = GetObject("LDAP://"&strContainer)
'Wscript.echo "objOU is: " & objOU
'29
strLDAPName = strLDAPName & strLastName &", "& strFirstName
'31
Wscript.echo "Unresolved LDAP Name is: " & strLDAPName
'33
Set objUser = GetObject("LDAP://cn="& strLDAPName & strContainer & strDContainer)
'35
If objUser.cn = strLDAPName then
WScript.echo "Resolved LDAP UserName is: " & objUser.cn
End if
WScript.quit