Yorn Posted October 15, 2007 Share Posted October 15, 2007 I downloaded adfunctions.au3, but I'm not finding the command I'm looking for. I want to pull ALL groups that a user is a member of as opposed to manually checking each one. Several commands in the file look like they will work, and they do not, here is what I have tried: _ADGetUserGroups(_ADSamAccountNameToFQDN(@Username)) The last one I think should work, but it errors with ByRef error. "ByRef $usergroups" That's part of the function. I don't know what $usergroups. should be, however, after all, I'm feeding it the user to find out what groups the user is a member of, I don't know what groups the user is a member of beforehand. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 16, 2007 Share Posted October 16, 2007 I downloaded adfunctions.au3, but I'm not finding the command I'm looking for. I want to pull ALL groups that a user is a member of as opposed to manually checking each one. Several commands in the file look like they will work, and they do not, here is what I have tried: _ADGetUserGroups(_ADSamAccountNameToFQDN(@Username)) The last one I think should work, but it errors with ByRef error. "ByRef $usergroups" That's part of the function. I don't know what $usergroups. should be, however, after all, I'm feeding it the user to find out what groups the user is a member of, I don't know what groups the user is a member of beforehand. Here's the relevant function from adfunctions.au3: ; _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) ; ... EndFunc ;==>_ADGetUserGroupsoÝ÷ ØÚ-zØ^ºÇ«ËazÇ¢wij¶¦z׫jwb±©ky§r¶ººÞÕ,z³ZæòuçÚº[l£*.Æ¥Ú &¦Ç(º{Mjg T6++yÛ§u©íN»-jwh«z«¢çij¶¦z׫ËaxyûÚ®&ëh¦ëm櫬¢8b²ÈhºWp¢¹ºÒj}ý¶×¬µ·jë#fbåjwZ¶Ø^Ö®¶sb6æ6ÇVFRfÇC¶'&æS2fwC°¢6æ6ÇVFRfÇC¶FgVæ7Föç2æS2fwC° ¤vÆö&Âb33c¶dw&÷W0¥ôDvWEW6W$w&÷W2b33c¶dw&÷W2¥ô'&F7Æb33c¶dw&÷W2ÂgV÷C´FV'Vs¢b33c¶dw&÷W2gV÷C² 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 Link to comment Share on other sites More sharing options...
Yorn Posted October 22, 2007 Author Share Posted October 22, 2007 (edited) Thanks, this is working now, I think I get some of the array stuff, but here's the code I have now: _ADGetUserGroups($avGroups) $grps = _ADDNToSamAccountName(_ArrayPop($avGroups)) While UBound($avGroups) > 0 $grps = $grps & ", " & _ADDNToSamAccountName(_ArrayPop($avGroups)) WEnd This code errors with "Badly formated variable or macro." but if I comment out the WHILE statement it *does* return the first element pop'd from the array. I'm certain the WHILE is breaking this, but I don't know why. I believe UBound is being used appropriately here given the example from the help file for _ArrayPoP, but it must be wrong or else it'd be working, right? Edited October 22, 2007 by Yorn Link to comment Share on other sites More sharing options...
Yorn Posted October 22, 2007 Author Share Posted October 22, 2007 When I changed the "> 0" to "> 1" it seems to have worked. It's missing "Domain Users", but that's not a major problem for me. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 22, 2007 Share Posted October 22, 2007 (edited) Thanks, this is working now, I think I get some of the array stuff, but here's the code I have now: _ADGetUserGroups($avGroups) $grps = _ADDNToSamAccountName(_ArrayPop($avGroups)) While UBound($avGroups) > 0 $grps = $grps & ", " & _ADDNToSamAccountName(_ArrayPop($avGroups)) WEnd This code errors with "Badly formated variable or macro." but if I comment out the WHILE statement it *does* return the first element pop'd from the array. I'm certain the WHILE is breaking this, but I don't know why. I believe UBound is being used appropriately here given the example from the help file for _ArrayPoP, but it must be wrong or else it'd be working, right? That's a very awkward way to do it, and produces an error when you try to use the integer value in [0]. Also, any variable use ByRef must be declared beforehand. The array returned by _ADGetUserGroups(), like with many AutoIt functions, has [0] = count. This will work much better: #include <adfunctions.au3> #include <array.au3> Dim $avGroups _ADGetUserGroups($avGroups) _ArrayDisplay($avGroups, "Debug: $avGroups") $grps = "" For $n = 1 to $avGroups[0] $grps &= _ADDNToSamAccountName($avGroups[$n]) & ", " Next $grps = StringTrimRight($grps, 2) MsgBox(64, "Debug", "Debug: $grps = " & $grps) Edit: Tweak to remove stray comma from the end of $grps string. Edited October 22, 2007 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 Link to comment Share on other sites More sharing options...
GEOSoft Posted October 22, 2007 Share Posted October 22, 2007 Use the code That PsaltyDS posted. As a Tip the right way to do the While loop that you tried would have been While UBound($avGroups)-1 > 0 George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Yorn Posted October 26, 2007 Author Share Posted October 26, 2007 Thanks for the help guys! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now