Jump to content

Failed to load user's memberships with ADODB


arcker
 Share

Recommended Posts

hi evryone, i'm again on my script for ldap, but i've a little problem of conversion (I think).

I want to show every group of a user (memberof), but doesn't seem to work.

I've sought on the entire forum, but no results.

Here is an example in vbs, for members of a group, from msdn ;

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
 "<GC://dc=NA,dc=fabrikam,dc=com>;(objectCategory=Group);" & _
 "distinguishedName,name,member;subtree"

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
 Wscript.Echo objRecordSet.Fields("Name")
 Wscript.Echo "[" & _
 objRecordSet.Fields("distinguishedName") & "]"

 Wscript.Echo "Group Member(s):"
 arrMembers = objRecordSet.Fields("member")

 If IsArray(objRecordSet.Fields("member")) Then
 For Each strMember in arrMembers
 Wscript.Echo vbTab & strMember
 Next
 Else
 Wscript.Echo vbTab & "None"
 End If
 Wscript.Echo VbCrLf
 objRecordSet.MoveNext
Wend

objConnection.Close

here is extract of my code, i think it's the same method for "member" and "memberOf" :

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)(sAMAccountName=*" & $l_UserId & "*))"
    Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName,memberOf"
    Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"
    $objCommand.CommandText = $strQuery
    $objCommand.Properties ("Page Size") = 100
    $objCommand.Properties ("Timeout") = 30
    $objCommand.Properties("Sort On") = "sAMAccountName"
    $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
        $strCN = $objRecordSet.Fields ("cn").value
        $strdisplayName = $objRecordSet.Fields ("displayName").value
        $strSN = $objRecordSet.Fields ("SN").value
   ;beginning of the problem
    $arrMembers = $objRecordSet.Fields ("memberOf")
    If IsArray($objRecordSet.Fields ("memberOf")) Then 
    for  $strMember in $arrMembers
        msgbox(0,"",$strMember) 
      Next
    wend

thanx for any help

ps : when i run the script, there is no error, so i think it's a problem with a array, i think of an

_arraycreate solution...but really not sure....

[...]

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

  • Developers

It works for me when changing these lines to:

$arrMembers = $objRecordSet.Fields ("memberOf").value
    If IsArray($arrMembers) Then
        For $strMember In $arrMembers
            ConsoleWrite('$strMember = ' & $strMember & @LF)
        Next
    EndIf
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...