Announcement

Collapse
No announcement yet.

Getting User's Description in AD

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting User's Description in AD

    I have the following script that allows be to pulls up the user's login by entering their first and last name, but I am having a hard time getting the description value. I can't figure out how to take the value returned from the lookup to get the description of the user. Any suggestions? Here is what I have now that get's the user id. I am trying to get the User ID to echo followed by the description.

    On Error Resume Next

    Const ADS_SCOPE_SUBTREE = 2

    strFName = ""
    strFName = InputBox("Please Enter First Name:", "First Name")

    Do While strFName = ""
    WScript.Echo "First Name is Required"
    strFName = InputBox("Please Enter First Name:", "First Name")
    Loop

    strLName = ""
    strLName = InputBox("Please Enter Last Name:", "First Last")

    Do While strLName = ""
    WScript.Echo "Last Name is Required"
    strLName = InputBox("Please Enter Last Name:", "Last Name")
    Loop

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

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

    objCommand.CommandText = _
    "SELECT Description FROM 'LDAP://DC=Anything,DC=COM' WHERE objectCategory='user' AND givenName='" & strFName & "' AND sn='" & strLName & "'"

    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
    Wscript.Echo ("User Login is: " & objRecordSet.Fields("Name")).Value
    objRecordSet.MoveNext
    Loop
    Thanks in advance.

    A
    Last edited by BigA; 7th November 2009, 14:03. Reason: Spelling
Working...
X