AD query - search AD for valid username w/input box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lookin4Toons
    New Member
    • Jun 2009
    • 3

    AD query - search AD for valid username w/input box

    Trying to create a text box w/user input to enter a suggested user name and query AD to see if the name is available. This is for HR users who do not have access to the Admin tools to open the container. Can this be written another way to "prompt" for user input somewhere else in the script?
    Thank you -

    On Error Resume Next
    Const ADS_SCOPE_SUBTR EE = 2
    strUSER = InputBox("Pleas e put the desired User Name:","USER")
    If strUSER = "" Then
    WScript.Echo "No User Name entered. Program aborted."
    Wscript.Quit
    End If
    On Error Resume Next
    Set objConnection = CreateObject("A DODB.Connection ")
    Set objCommand = CreateObject("A DODB.Command")
    objConnection.P rovider = ("ADsDSOObject" )
    objConnection.O pen "Active Directory Provider"
    objCommand.Acti veConnection = objConnection
    objUser = GetObject ("'LDAP://OU=xx,dc=xx,dc= xx,dc=xx'" & obj.User.UserNa me)
    objCommand.Comm andText = "SELECT samAccountName FROM " & _
    "'LDAP://OU=xx,dc=xx,dc= xx,dc=xx'" & _
    "WHERE samAccountName = %strUser%"
    objCommand.Prop erties("SearchS cope") = ADS_SCOPE_SUBTR EE
    Set objRecordSet = objCommand.Exec ute
    If objRecordSet.Re cordCount = 0 Then
    Wscript.Echo "The Account name is not being used."
    Else
    Wscript.Echo "The Account name is being used. Please choose another name."
    End If
    Last edited by debasisdas; Jun 16 '09, 09:25 PM. Reason: mail id snipped.
  • Lookin4Toons
    New Member
    • Jun 2009
    • 3

    #2
    Figured it out after several attempts:
    Now I need to figure out if the name exists, how to loop back to check another

    On Error Resume Next
    Const ADS_SCOPE_SUBTR EE = 2
    Dim Fname
    strFname = InputBox("Pleas e put the desired User Name:",Fname)
    If strFname = "" Then
    WScript.Echo "No User Name entered. Program aborted."
    Wscript.Quit
    End If
    Set objConnection = CreateObject("A DODB.Connection ")
    Set objCommand = CreateObject("A DODB.Command")
    objConnection.P rovider = ("ADsDSOObject" )
    objConnection.O pen "Active Directory Provider"
    objCommand.Acti veConnection = objConnection
    objCommand.Comm andText = "SELECT ScriptPath FROM 'LDAP://OU=xxx,dc=ad,dc =xx,dc=xxx' WHERE objectCategory= 'user'" & _
    "AND sAMAccountName= '" & strFname & "'"
    objCommand.Prop erties("SearchS cope") = ADS_SCOPE_SUBTR EE
    Set objRecordSet = objCommand.Exec ute
    If objRecordSet.Re cordCount = 0 Then
    Wscript.Echo "The Account:"&strFn ame& " name is not being used."
    Else
    Wscript.Echo "The Account "&strFname& " is being used. Please choose another name."
    End If

    Comment

    • Lookin4Toons
      New Member
      • Jun 2009
      • 3

      #3
      need to insert loop back into process

      Now that I have figured out how to get the basics, how do I insert a If Then to loop it back if they want to retry if they name exists.
      Same question if the name is OK if they would like to check another name.
      Should I use the MsgBox at this point?

      Comment

      Working...