Aen Posted December 11, 2008 Share Posted December 11, 2008 Writing a script that basically does this:1. Ask user for a username2. Ask user for employee number3. script verifies if it is real username - if it is, continues - if not, it stops script4. (step i need help with) - Query AD through LDAP and pull DN5. Add employee number to 2 different fields in AD (employeeID, employeeNumber)Real simple script.. but having some issues getting the DN from AD.*DN = distinguishedNameHere is what i got: Set objFile = CreateObject("Scripting.FileSystemObject")Set objNetName = CreateObject("WScript.NetWork") DIM strEmpIDName = GetUserName()EmployeeID = GetEmployeeID()UserExists = CheckUser(Name)If UserExists = TRUE thenmsgbox strEmpIDmsgbox NameCall LoadEmployeeIDElseMsgbox "User does not exist, try again."wscript.quit(0)End If'===========================Function LoadEmployeeID()Set objUser = GetObjectobjUser.Put "employeeNumber", strEmpID'objUser.Put "employeeID", EmployeeIDobjUser.SetInfoEnd Function'===========================Function GetEmployeeID()EmployeeID = Inputbox ("Please enter in 5 digit employee number")strEmpID = EmployeeIDEnd Function'=======================================Function GetUserName()i = 0UserName = InputBox ("Ex. Firstname.LastName ", " Please Enter User Name")Do While Instr(UserName, ".") = 0 and i <= 5Username = InputBox ("Ex. Firstname.LastName ", " Please Enter User Name")i=i+1LoopIf Instr(UserName, ".") = 0 ThenWScript.Quit(0)ElseGetUserName = Trim(UserName)End IfEnd Function'===========================================Function CheckUser(strUserName)dtStart = TimeValue(Now())Set objConnection = CreateObject("ADODB.Connection")objConnection.Open "Provider=ADsDSOObject;"Set objCommand = CreateObject("ADODB.Command")objCommand.ActiveConnection = objConnectionobjCommand.CommandText = _ "<LDAP:/*removed*t>;(&(objectCategory=User)" & _ "(samAccountName=" & strUserName & "));samAccountName;distinguishedName;subtree"Set objRecordSet = objCommand.ExecuteIf objRecordset.RecordCount = 0 Then 'WScript.Echo "sAMAccountName: " & strUserName & " does not exist." CheckUser = FALSEElse objRecordset.MoveFirst Do while Not objRecordset.EOF wscript.echo objRecordset("samAccountName") & " | " & objRecordset("distinguishedName") objRecordset.MoveNext Loop 'WScript.Echo strUserName & " exists." CheckUser = TRUEEnd IfobjConnection.CloseEnd Function'====================================================Can anyone please give some advice or code that can help?I think if i can just pull the DN from LDAP query and put that into a variable..i can finish the rest. Link to comment Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!Register a new account
Already have an account? Sign in here.Sign In Now