Jump to content
Sign in to follow this  
EndFunc

Yet another AD function

Recommended Posts

EndFunc

OK I'm trying to call this function from the AD functinos UDF and I just can't get it to work.

What are the parameters that are entered to use the function. Anyone have an example of how to call this function.

Not understanding the the ByRef.

Also I don't want to use the default logged in user but specify a user.

; _ADGetUserGroups
; the currently logged on user is a member of. Returns an array of Full DNs of the Group names that the user is immediately a member of
; with element 0 containing the number of groups.
; $user - optional -- SamAccountName of a user, defaults to locally logged on user

Func _ADGetUserGroups(ByRef $usergroups, $user = @UserName)
    Local $oUsr
    
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute($strQuery) ; Retrieve the FQDN for the logged on user
    $ldap_entry = $objRecordSet.fields(0).value
    $oUsr = _ADObjGet($ldap_entry) ; Retrieve the COM Object for the logged on user
    
    $usergroups = $oUsr.GetEx("memberof")
    
    $oUsr = 0
    
    $count = UBound($usergroups)
    _ArrayInsert($usergroups, 0, $count)
EndFunc   ;==>_ADGetUserGroups
Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
PsaltyDS

OK I'm trying to call this function from the AD functinos UDF and I just can't get it to work.

What are the parameters that are entered to use the function. Anyone have an example of how to call this function.

Not understanding the the ByRef.

Also I don't want to use the default logged in user but specify a user.

; _ADGetUserGroups
; the currently logged on user is a member of. Returns an array of Full DNs of the Group names that the user is immediately a member of
; with element 0 containing the number of groups.
; $user - optional -- SamAccountName of a user, defaults to locally logged on user

Func _ADGetUserGroups(ByRef $usergroups, $user = @UserName)
    Local $oUsr
    
    $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $user & ");ADsPath;subtree"
    $objRecordSet = $objConnection.Execute($strQuery); Retrieve the FQDN for the logged on user
    $ldap_entry = $objRecordSet.fields(0).value
    $oUsr = _ADObjGet($ldap_entry); Retrieve the COM Object for the logged on user
    
    $usergroups = $oUsr.GetEx("memberof")
    
    $oUsr = 0
    
    $count = UBound($usergroups)
    _ArrayInsert($usergroups, 0, $count)
EndFunc ;==>_ADGetUserGroups
After 266 posts since March, 2007 you don't know what ByRef is for?

;)

ByRef means the variable given in the input parameter will be altered by the function. You cannot pass a literal string, it must be a previously declared variable which will be altered when used by the function:

#include <Array.au3>

Global $avGroups
Global $sUser = "MyFunkyUser"

_ADGetUserGroups($avGroups, $sUser)

_ArrayDisplay($avGroups, "Groups")

Internally to the function, whenever the local $usergroups is used, the global $avGroups gets modified "By Reference".

^_^

Edited by PsaltyDS

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  

×