Bearpocalypse Posted September 11, 2018 Share Posted September 11, 2018 Longtime no see everyone! I haven't had a chance to do some coding in a while since some management has decided that innovation was just awful since they didn't understand it. It's been a couple of years since I've actually produced anything. I have now taken a new position within the same company with a new manager who salivates at innovation. My new role involves doing a lot of account management, like a Sys Admin but I'm not a Sys Admin. Anyways, I'm throwing together a script to pull a users group memberships and users who are members of a certain group. Both requests seem to come often. We don't have a quick pull up and export tool, so I'm making one. I'm using AD.au3 to get the members and populate into a listbox. I think I've gone full potato because I cannot for the life of me figure out how to remove the OU information from the strings. Example, I have a list of stuff that looks like this: Group-Thing,OU=Place1,OU=Place2,OU=Place3 I'm wanting to remove everything past the first comma. I used a simple StringTrimLeft to remove the CN= from the string. By just pulling straight from AD like this am I doing it wrong or is there a different way to pull Group-Thing by itself? Here is my very very early code, like this is what I tossed together in about 10 mins, design time from Koda included. Forgive me for being rather rusty. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <AD.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Group Soup", 483, 403) $Input1 = GUICtrlCreateInput("", 32, 64, 169, 21) $Group1 = GUICtrlCreateGroup("User Group Lookup", 16, 40, 201, 73) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Group Member Lookup", 16, 160, 201, 73) $Input2 = GUICtrlCreateInput("", 32, 192, 169, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $List1 = GUICtrlCreateList("", 240, 40, 225, 331) $Button1 = GUICtrlCreateButton("User Group", 16, 120, 91, 25) $Button2 = GUICtrlCreateButton("Group Members", 16, 240, 91, 25) $Button3 = GUICtrlCreateButton("Export", 128, 120, 91, 25) $Button4 = GUICtrlCreateButton("Export", 128, 240, 91, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _List_User_Groups(GUICtrlRead($Input1)) EndSwitch WEnd Func _List_User_Groups($User) ; Open Connection to the Active Directory _AD_Open() If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) ; Get a sorted array of group names (FQDN) that the user is immediately a member of Global $aUser = _AD_GetUserGroups($User) If @error > 0 Then MsgBox(64, "Active Directory Functions - Example 1", "User '" & $User & "' has not been assigned to any group") Else For $i = 1 To UBound($aUser) - 1 GUICtrlSetData($List1, StringTrimLeft($aUser[$i], 3)) Next EndIf ; Close Connection to the Active Directory _AD_Close() EndFunc Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 11, 2018 Share Posted September 11, 2018 30 minutes ago, Bearpocalypse said: I'm making one. I'm using AD.au3 to get the members and populate into a listbox. I think I've gone full potato because I cannot for the life of me figure out how to remove the OU information from the strings. Example, I have a list of stuff that looks like this: Group-Thing,OU=Place1,OU=Place2,OU=Place3 Premising that I don't know anything about AD, if you're trying to do this, use StringSplit(), and build your string as you want Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 11, 2018 Moderators Share Posted September 11, 2018 @Bearpocalypse building on what FrancescoDiMuro stated, try something like this, should give you at least an idea that you can build off of. ;Replacement for your For Loop: For $i = 1 To UBound($aUser) - 1 $aTemp = StringSplit($aUser[$i], ",") If IsArray($aTemp) Then GUICtrlSetData($List1, StringReplace($aTemp[1], "CN=", "")) Next Now, one of our "regexperts" may come along and speed that up, but StringReplace seems to work fairly quickly against my AD account and its 200 groups FrancescoDiMuro 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Bearpocalypse Posted September 11, 2018 Author Share Posted September 11, 2018 Thanks @FrancescoDiMuro and @JLogan3o13 . That gives me exactly what I need. I can now build off that and do more witchcraft that I used to be able to do. 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