Page 1 of 1 1
Topic Options
#198538 - 2010-05-04 09:54 AM Problem with the result of fnLDAPQuery
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
Hi everyone!

I'm trying to list groups and descriptions from AD by using fnLDAPQuery.

I have it working, but It's a workaround...
In the script I ask for "cn" and "description, but I can only get the cn-part.
So to get the description I use an extra GETObject(), witch get what I want, but that means I'm sending close to 600 extra requests :-/

I have messed around with different for.. next-loops ,but to no avail.

Here's the "working" code:

 Code:
Dim $grpWhat, $grpFrom, $grpfilter, $grpResult, $objPackDesc
Dim $j, $packDesc

$grpWhat = "cn", "description"
$grpFrom = "LDAP://" + $CmpGrpPath
$grpfilter = "(&(objectCategory=group)(cn=Pack*))"


$grpResult = fnLDAPQuery($grpWhat,$grpFrom,$grpfilter)

For $j = 0 To Ubound($grpResult)

    $objPackDesc = GetObject('LDAP://CN="' + $grpResult[$j,0] + '",OU="Groups Computers",OU=LIVNET,DC=liv,DC=se')
    $packDesc = $objPackDesc.description

    If $packDesc
      AT(5,1) ? $grpResult[$j,0]
      AT(6,1) ? $packDesc
    Else
      AT(5,1) ? $grpResult[$j,0]
    Endif
Next


AT(8,1) ? "Done..."
Get $x
Exit



Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
    
    Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
    
    $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),
        $From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+
        Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
    
    $oCon=CreateObject("ADODB.Connection")
    $oCon.Provider="ADsDSOObject"
    $oCon.Properties("Encrypt Password").Value=1
    $oCon.Properties("ADSI Flag").Value=1
    If $User AND $Pswd
        $oCon.Properties("User ID").Value=$User
        $oCon.Properties("Password").Value=$Pswd
    EndIf
    $oCon.Open("Active Directory Provider")
     
    $oCMD=CreateObject("ADODB.Command")
    $oCMD.ActiveConnection=$oCon
    $oCMD.CommandText=$sQ
    $oCMD.Properties("Page Size").Value=1000
    $oCMD.Properties("Timeout").Value=30
    $oCMD.Properties("Cache Results").Value=0
    
    If InStr($OrderBy,"distinguishedName")
        $oRS=CreateObject("ADODB.Recordset")
        $oRS.CursorLocation=3
        $oRS.Sort=$OrderBy
        $oRS.Open($sQ,$oCon,0,1,1)
    Else
        If $OrderBy
            $oCMD.Properties("Sort On").Value=$OrderBy
        EndIf
        $oRS=$oCMD.Execute
    EndIf
    If @ERROR Exit @ERROR EndIf
    If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf
    
    $aR = $oRS.GetRows()
    Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
    For $R=0 to Ubound($aR,2)
        For $C=0 to Ubound($aR,1)
            $aFR[$R,$C]=$aR[$C,$R]
        Next
    Next
    
    $fnLDAPQuery=$aFR
EndFunction


Any suggestions?

/Viggen

Top
#198544 - 2010-05-04 04:12 PM Re: Problem with the result of fnLDAPQuery [Re: Viggen]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Modified the example in the fnLDAPQuery() documentation...

 Code:
 ; == Return the Name, AdsPath and members of all groups =========
 $aAttributes = "cn", "description" ; "Name", "AdsPath", "member"
 $sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
 $strFilter = "(&(objectClass=group)(cn=Pack*))"

 $aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter)
 @ERROR " | " @SERROR ?

 For $c = 0 to Ubound($aResults)
     For $r = 0 to UBound($aResults,2)
         "=============================" ?
         If VarType($aResults[$c,$r])>8192
            "  Description:" ?
            For Each $rr in $aResults[$c,$r]
                "   " $rr ?
            Next
         Else
            $aResults[$c,$r] ?
         EndIf
     Next
     ?
 Next

Top
#198545 - 2010-05-04 05:26 PM Re: Problem with the result of fnLDAPQuery [Re: Chris S.]
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
Errmmm...

Just checked that part out in my udf (I removed it for this post), and I haven't got that example...

I have the first one, but somehow I must have erased the second one.

That solution works great!
Thanks alot!

/Viggen

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 601 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.142 seconds in which 0.118 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org