Sign in to follow this  
Followers 0
jwc

Retrieve information from Active Directory

2 posts in this topic

Please help, I'm new to AutoIt. This should be a sinch for you programmers :whistle:

I wan't to retrieve user information such as "Office" and "Description" for the currently logged on user from active directory and assign the data to a variable that I create.

Ex. If John Doe is logged on to the network, in active directory, his information is as follows:

Office=Rm 513

Description=Accountant

I want to create 2 variables $useroffice and $userdescription and populate these variables with the corresponding active directory data.

I am not a programmer, I'm simply trying to hack this into place! Any help would be GREATLY appreciated.

:">

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The following code is from a script I use to find users and do some processing on them. Perhaps it may point you in the right direction.

Func btnSearchonclick()
 $UserDomain = "dc=engineering,dc=bb,dc=wan"
 $l_UserId = GUICtrlRead($edtUser)
 _GUICtrlListViewDeleteAllItems($lstResults)
 
    Local $objCommand = ObjCreate("ADODB.Command")
    Local $objConnection = ObjCreate("ADODB.Connection")
    $objConnection.Provider = "ADsDSOObject"
    $objConnection.Open ("Active Directory Provider")
    $objCommand.ActiveConnection = $objConnection
 
    Local $strBase = "<GC://" & $UserDomain & ">"
    Local $strFilter = "(&(objectCategory=person)(objectClass=user)(cn=*" & $l_UserId & "*))"
    Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName"
    Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"

 $objCommand.CommandText = $strQuery
    $objCommand.Properties ("Page Size") = 100
    $objCommand.Properties("Sort On") = "cn"
    $objCommand.Properties ("Timeout") = 30
    $objCommand.Properties ("Cache Results") = False
    $ADS_SCOPE_SUBTREE = 2
    $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE
 
    Local $objRecordSet = $objCommand.Execute
    While Not $objRecordSet.EOF
        $strName = $objRecordSet.Fields ("sAMAccountName").Value
        $strdisplayName = $objRecordSet.Fields ("displayName").value
        $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value
  GUICtrlCreateListViewItem($strName&"|"&$strdisplayName&"|"&$strdistinguishedName, $lstResults)
        $objRecordSet.MoveNext
    WEnd
    $objConnection.Close
EndFunc
Edited by sandyd

----[ SandyD ]---

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0