Sign in to follow this  
Followers 0
Kilhian

Active Directory query, array and object problems

4 posts in this topic

#1 ·  Posted (edited)

Hi, i'am trying to get all mails from each user of my AD.

i ve tried this:

#include <adfunctions.au3>
#include <array.au3>
Const $ADS_NAME_INITTYPE_GC = 3
Const $ADS_NAME_TYPE_NT4 = 3
Const $ADS_NAME_TYPE_1779 = 1
    $objTrans = ObjCreate("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
    $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
Dim $test[999999]
;Dim $mail[5]
Dim $objectarray
$ou = "ou=xxx,dc=xxx,dc=xxx"
_ADGetObjectsInOU_moded($objectarray, $ou, "(&(objectCategory=person)(objectClass=user))", 2,"sAMAccountName","sAMAccountName")
_ArrayDisplay($objectarray)





; _ADGetObjectsInOU_moded

Func _ADGetObjectsInOU_moded(ByRef $ObjectArray, $ou, $filter = "(name=*)", $searchscope = 2, $datatoretrieve = "sAMAccountName", $sortby = "sAMAccountName")
    Local $objRecordSet
    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties ("Page Size") = 256
    $objCommand.Properties ("Searchscope") = $searchscope
    $objCommand.Properties ("TimeOut") = 20
    $strCmdText = "<LDAP://" & $strHostServer & "/" & $ou & ">;" & $filter & ";" & $datatoretrieve & ";subtree"
    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute
    $recordcount = $objRecordSet.RecordCount
    If $recordcount = 0 Then
        $objCommand = 0
        $objRecordSet = 0
        Return 0
    EndIf
        Dim $ObjectArray[$recordcount + 1]
        $ObjectArray[0] = UBound($ObjectArray) - 1
        If $ObjectArray[0] = 0 Then
            $ObjectArray = 0
            Return 0
        Else
            $count = 1
            $k=0
            $objRecordSet.MoveFirst
            Do
                $ObjectArray[$count] = $objRecordSet.Fields ($datatoretrieve).Value
                        $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $ObjectArray[$count])
                    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
                    $UserObj = ObjGet("LDAP://" & $strUserDN)
                    $mail=$UserObj.PROXYAddressES
                    _ArrayDisplay($mail); show email in an array
                    MsgBox(0,"",$mail[1]); show an error
                    For $i =0 to UBound($mail-1)
                        $test[0][$k]=$ObjectArray[$count] ;username
                        $test[1][$k]=$mail[$i];email
                        $k+=1
                    Next
                    ;_ArrayDisplay($UserObj.PROXYAddressES); works too

                $objRecordSet.MoveNext
                $count += 1
            Until $objRecordSet.EOF
        EndIf
    
    $objCommand = 0
    $objRecordSet = 0
    
    Return 1
    
EndFunc   ;==>_ADGetObjectsInOU
but it seems too much complicated to get an array:

user1 mail1

user1 mail2

user1 mail3

user2 mail1

...

mail are stored in userADobj.proxyadresses

Thanks for the help

Edited by Kilhian

Share this post


Link to post
Share on other sites



No hints?

Share this post


Link to post
Share on other sites

No idea where i am wrong

Share this post


Link to post
Share on other sites

Last up...

76 read.. nobody could help me to resolve this array/object problem...

So bad

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