Sign in to follow this  
Followers 0
pjw73nh

Enumerate AD group members. Found this. Errors

8 posts in this topic

Greetings,

I am trying to write/find a script that will enumerate AD group members of specific groups in a list type format. Preferrably to a file.

I found this over in example scripts:

; GetGroupMembers
; Arguments,
; $members - Array that the result will be stored in
; $group - Group to retrieve members from
; $sort - optional, default 0 : Set to 1 to sort the array
; Returns an array to $members where $members[0] will be the number of users in the group and
; $members[1] to $members[$members[0]] are the distinguished names of the users

Func GetGroupMembers(ByRef $members, $group, $sort = 0)
If ObjectExists($group) = 0 Then Return 0

Dim $objConnection, $oUsr, $objCommand

Local $groups

$objConnection = ObjCreate("ADODB.Connection"); Create COM object to AD
$objCommand = ObjCreate("ADODB.Command")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open ("Active Directory Provider"); Open connection to AD
$objCommand.ActiveConnection = $objConnection
$objCommand.Properties ("Searchscope") = 2

$objRootDSE = ObjGet("LDAP://RootDSE")
Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext"); Retrieve the current AD domain name

$strCmdText = "<LDAP://" & $strDNSDomain & ">;(sAMAccountName=" & $group & ");distinguishedname;Subtree"
$objCommand.CommandText = $strCmdText
$objRecordSet = $objCommand.Execute

$ObjGroup = ObjGet("LDAP://" & $objRecordSet.fields ("DistinguishedName").Value)
Dim $members[1]
$i = 0

While 1
$rangemodifier = $i * 1000
$range = "Range=" & $rangemodifier & "-" & $rangemodifier + 999
$strCmdText = "<LDAP://" & $objGroup.distinguishedname & ">;;member;" & $range & ";base"
$objCommand.CommandText = $strCmdText
$objRecordSet = $objCommand.Execute
$membersadd = $objRecordSet.fields (0).Value
If $membersadd = 0 Then ExitLoop
For $j = 0 To 999
_ArrayAdd($members, $membersadd[$j])
Next
$i += 1
$objRecordSet.Close
WEnd

$rangemodifier = $i * 1000
$range = "Range=" & $rangemodifier & "-*"
$strCmdText = "<LDAP://" & $objGroup.distinguishedname & ">;;member;" & $range & ";base"
$objCommand.CommandText = $strCmdText
$objRecordSet = $objCommand.Execute
$membersadd = $objRecordSet.fields (0).Value
For $j = 0 To UBound($membersadd) - 1
_ArrayAdd($members, $membersadd[$j])
Next

$objRecordSet.Close

$members[0] = UBound($members) - 1

If $sort = 1 Then
_ArraySort($members, 0, 1)
EndIf

Return 1
EndFunc;==>GetGroupMembers

I am not sure I know how to use it. Where do I enter (what do I change) to input my specific information? FQDN, group name etc?

I get this error when I run a syntax check.

>C:\Program Files\AutoIt3\SciTE\CompileAU3\CompileAU3.exe /prod /AU3Check /in "H:\GetVPn.au3"
>Running AU3Check...C:\Program Files\AutoIt3\SciTe\Defs\Production\Au3Check\au3check.dat
H:\GetVPn.au3(11,23) : ERROR: ObjectExists(): undefined function.
If ObjectExists($group)
~~~~~~~~~~~~~~~~~~~~~~^
H:\GetVPn.au3(44,36) : ERROR: _ArrayAdd(): undefined function.
_ArrayAdd($members, $membersadd[$j])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
H:\GetVPn.au3(65,26) : ERROR: _ArraySort(): undefined function.
_ArraySort($members, 0, 1)
~~~~~~~~~~~~~~~~~~~~~~~~~^
H:\GetVPn.au3 - 3 error(s), 0 warning(s)
>AU3Check Ended with Error(s).
>Exit code: 0   Time: 0.437

Thanks for any help you can provide.

Paul...

Share this post


Link to post
Share on other sites



You are using a function that does not exist or is not defined : ObjectExists()

Func GetGroupMembers(ByRef $members, $group, $sort = 0)

If ObjectExists($group) = 0 Then Return 0

...

Share this post


Link to post
Share on other sites

You are using a function that does not exist or is not defined : ObjectExists()

Where would I (do I) define it. and in what format ? FQDN?

Tnx

Share this post


Link to post
Share on other sites

Where would I (do I) define it. and in what format ? FQDN?

Tnx

Where did you get the function you quoted? It is likely part of a set of functions all included in one UDF. You would just put the appropriate #include at the top of your script to get all the parts at once.

The call to the function would look like this:

#include <array.au3> ; For _ArrayDisplay()
#include <UDF_File_Name.au3>

Dim $sGroup_Name = "Users"
Dim $avList_Of_Members

GetGroupMembers($avList_Of_Members, $sGroup_Name)
_ArrayDisplay($avList_Of_Members, "Members of group: " & $sGroup_Name)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Where did you get the function you quoted? It is likely part of a set of functions all included in one UDF. You would just put the appropriate #include at the top of your script to get all the parts at once.

The call to the function would look like this:

#include <array.au3> ; For _ArrayDisplay()
#include <UDF_File_Name.au3>

Dim $sGroup_Name = "Users"
Dim $avList_Of_Members

GetGroupMembers($avList_Of_Members, $sGroup_Name)
_ArrayDisplay($avList_Of_Members, "Members of group: " & $sGroup_Name)

:)

Thanks for the quick reply. Sorry to be such a pain about this.

I found the script here:

THis Link Edited link

What did I miss? Thanks again. I know it's difficult teaching a newbie.. I appreciate all of your patience...

Thanks

Edited by pjw73nh

Share this post


Link to post
Share on other sites

Thanks for the quick reply. Sorry to be such a pain about this.

I found the script here:

THis Link Edited link

What did I miss? Thanks again. I know it's difficult teaching a newbie.. I appreciate all of your patience...

Thanks

You change the link while I was posting my smart-alec response about the recursive link back to the same topic... ;)

At minimum, you need the function ObjectExists() from that page, and the array.au3 that comes with AutoIt. So you put #include <array.au3> at the top of your script, and copy in the ObjectExists() function (since it isn't in a UDF file). You'll have to see if ObjectExists() in turn requires another function.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You change the link while I was posting my smart-alec response about the recursive link back to the same topic... ;)

At minimum, you need the function ObjectExists() from that page, and the array.au3 that comes with AutoIt. So you put #include <array.au3> at the top of your script, and copy in the ObjectExists() function (since it isn't in a UDF file). You'll have to see if ObjectExists() in turn requires another function.

:)

OK I've got the array.au3 in. But I don't see where to get ObjectExists from. I see in the adfunctions.au3 download,(that is in my inculde folder) there is a section called _ADObjectExists, but I don't see one that just shows ObjectExists. Can (should) I use #include <adfunctions.au3> in the script? I guess I'm not too well versed on how to use functions.

Thanks

Share this post


Link to post
Share on other sites

If you looked at the AD functions topic you linked above, and download the latest version (it was just updated 9-25-07 -- last week), you will see the function you are trying to use has been replaced with a newer one called _ADGetGroupMembers():

; _ADGetGroupMembers
; Arguments,
; $members - Array that the result will be stored in
; $group - Group to retrieve members from
; $sort - optional, default 0 : Set to 1 to sort the array
; Returns an array to $members where $members[0] will be the number of users in the group and
; $members[1] to $members[$members[0]] are the distinguished names of the users

Func _ADGetGroupMembers(ByRef $members, $groupdn, $sort = 0)
    ;If _ADObjectExists($group) = 0 Then Return 0
    
    Local $oUsr, $objCommand, $groups

    $objCommand = ObjCreate("ADODB.Command")
    $objCommand.ActiveConnection = $objConnection
    $objCommand.Properties ("Searchscope") = 2

    Dim $members[1]
    $i = 0

    While 1
        $rangemodifier = $i * 1000
        $range = "Range=" & $rangemodifier & "-" & $rangemodifier + 999
        $strCmdText = "<LDAP://" & $strHostServer & "/" & $groupdn & ">;;member;" & $range & ";base"
        $objCommand.CommandText = $strCmdText
        $objRecordSet = $objCommand.Execute
        $membersadd = $objRecordSet.fields (0).Value
        If $membersadd = 0 Then ExitLoop
        ReDim $members[UBound($members) + 1000]
        For $j = $rangemodifier + 1 To $rangemodifier + 1000
            $members[$j] = $membersadd[$j - $rangemodifier - 1]
        Next
        $i += 1
        $objRecordSet.Close
    WEnd

    $rangemodifier = $i * 1000
    $range = "Range=" & $rangemodifier & "-*"
    $strCmdText = "<LDAP://" & $strHostServer & "/" & $groupdn & ">;;member;" & $range & ";base"
    $objCommand.CommandText = $strCmdText
    $objRecordSet = $objCommand.Execute
    $membersadd = $objRecordSet.fields (0).Value

    ReDim $members[UBound($members) + UBound($membersadd) ]

    For $j = $rangemodifier + 1 To $rangemodifier + UBound($membersadd)
        $members[$j] = $membersadd[$j - $rangemodifier - 1]
    Next

    $objRecordSet.Close
    
    $objCommand = 0
    $objRecordSet = 0
    
    $members[0] = UBound($members) - 1
    
    If $sort = 1 Then
        _ArraySort($members, 0, 1)
    EndIf
    
    Return 1
EndFunc   ;==>_ADGetGroupMembers

It still uses array.au3, but doesn't seem to call any other UDF functions. You could copy/paste that function into your script or just get the latest version of adfunctions.au3 copied to the Include folder and put #include <adfunctions.au3> at the top of your script.

My preference would be for the newer version.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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