Jump to content
Valnurat

Little advice

Recommended Posts

Valnurat
Func FindADInfo()
    Local $sUsersSource, $sBackupFolder, $sSiteHomePath, $sFileOpenDialog
    Local $aSamAccountName[0][1], $aAllSamAccounts[0][1]
    For $i = 0 to UBound($aAllMailSites) - 1
        if $aAllMailSites[$i][1] <> "" then
            if $bDebugMode Then
                ConsoleWrite("Collecting AD info for " & StringRight($aAllMailSites[$i][1], 2) & StringMid($aAllMailSites[$i][1], StringInStr($aAllMailSites[$i][1], ",") - 2, 2) & @CRLF)
            Else
                _FileWriteLog($hFile, "Collecting AD info for " & StringRight($aAllMailSites[$i][1], 2) & StringMid($aAllMailSites[$i][1], StringInStr($aAllMailSites[$i][1], ",") - 2, 2))
            EndIf
            $aSamAccountName = _AD_GetObjectsInOU($aAllMailSites[$i][1] & $sCompany, "(&(objectcategory=person)(objectclass=user))",2, "sAMAccountName,distinguishedName,displayname", "displayname")
            _ArrayDelete($aSamAccountName, 0)
            for $x = 0 to UBound($aSamAccountName) -1
                if StringInStr($aSamAccountName[$x][1],"Resources") = 0 Then
                    Local $iValue = ''
                    Local $aUserGroups = _AD_GetUserGroups($aSamAccountName[$x][1])
                    If IsArray($aUserGroups) Then
                        Local $bMailGroup = False, $bOfficegroup = False
                        For $y = 1 To UBound($aUserGroups) - 1
                            For $z = 1 To $aADOfficeGroups[0]
                                If StringInStr($aUserGroups[$y], $aADOfficeGroups[$z]) Then $bOfficeGroup = True
                            Next
                            If StringInStr($aUserGroups[$y], $aAllMailSites[$i][2],1) Then
                                $bMailGroup = True
                                Local $sRemoveGroup = $aUserGroups[_ArraySearch($aUserGroups,$aAllMailSites[$i][2],0,0,0,1,1)]
                            EndIf
                        Next
                        If $bOfficeGroup = True And $bMailGroup = False Then
                            If StringInStr("N/A",$aAllMailSites[$i][3]) = 0 Then
                                $iValue = _AD_AddUserToGroup($aAllMailSites[$i][3], $aSamAccountName[$x][1])
                                if $bDebugMode Then
                                    If $iValue = 1 Then
                                        ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' successfully assigned to group '" & $aAllMailSites[$i][3] & "'" & @CRLF)
                                    ElseIf @error = 1 Then
                                        ConsoleWrite("Group '" & $aAllMailSites[$i][3] & "' does not exist" & @CRLF)
                                    ElseIf @error = 2 Then
                                        ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' does not exist" & @CRLF)
                                    ElseIf @error = 3 Then
                                        ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' is already a member of group '" & $aAllMailSites[$i][3] & "'" & @CRLF)
                                    Else
                                        ConsoleWrite("Return code '" & @error & "' from Active Directory" & @CRLF)
                                    EndIf
                                Else
                                    If $iValue = 1 Then
                                        _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' successfully assigned to group '" & $aAllMailSites[$i][3] & "'" & @CRLF)
                                    ElseIf @error = 1 Then
                                        _FileWriteLog($hFile, "Group '" & $aAllMailSites[$i][3] & "' does not exist" & @CRLF)
                                    ElseIf @error = 2 Then
                                        _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' does not exist" & @CRLF)
                                    ElseIf @error = 3 Then
                                        _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' is already a member of group '" & $aAllMailSites[$i][3] & "'" & @CRLF)
                                    Else
                                        _FileWriteLog($hFile, "Return code '" & @error & "' from Active Directory" & @CRLF)
                                    EndIf
                                EndIf
                            EndIf
                        EndIf
                        If $bOfficeGroup = False And $bMailGroup = True Then
                            $iValue = _AD_RemoveUserFromGroup($sRemoveGroup, $aSamAccountName[$x][1])
                            if $bDebugMode Then
                                If $iValue = 1 Then
                                    ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' successfully removed from group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "'" & @CRLF)
                                ElseIf @error = 1 Then
                                    ConsoleWrite("Group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "' does not exist" & @CRLF)
                                ElseIf @error = 2 Then
                                    ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' does not exist" & @CRLF)
                                ElseIf @error = 3 Then
                                    ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' is not a member of group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "'" & @CRLF)
                                Else
                                    ConsoleWrite("Return code '" & @error & "' from Active Directory" & @CRLF)
                                EndIf
                            Else
                                If $iValue = 1 Then
                                    _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' successfully removed from group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "'" & @CRLF)
                                ElseIf @error = 1 Then
                                    _FileWriteLog($hFile, "Group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "' does not exist" & @CRLF)
                                ElseIf @error = 2 Then
                                    _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' does not exist" & @CRLF)
                                ElseIf @error = 3 Then
                                    _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' is not a member of group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "'" & @CRLF)
                                Else
                                    _FileWriteLog($hFile, "Return code '" & @error & "' from Active Directory" & @CRLF)
                                EndIf
                            EndIf
                        EndIf
                        If $bOfficeGroup = True And $bMailGroup = True Then
                            If StringInStr($aSamAccountName[$x][1],"Leavers") <> 0 Then
                                $iValue = _AD_RemoveUserFromGroup($sRemoveGroup, $aSamAccountName[$x][1])
                                if $bDebugMode Then
                                    If $iValue = 1 Then
                                        ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' successfully removed from group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "' because account is in leavers." & @CRLF)
                                    ElseIf @error = 1 Then
                                        ConsoleWrite("Group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "' does not exist" & @CRLF)
                                    ElseIf @error = 2 Then
                                        ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' does not exist" & @CRLF)
                                    ElseIf @error = 3 Then
                                        ConsoleWrite("User '" & $aSamAccountName[$x][2] & "' is not a member of group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "'" & @CRLF)
                                    Else
                                        ConsoleWrite("Return code '" & @error & "' from Active Directory" & @CRLF)
                                    EndIf
                                Else
                                    If $iValue = 1 Then
                                        _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' successfully removed from group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "' because account is in leavers." & @CRLF)
                                    ElseIf @error = 1 Then
                                        _FileWriteLog($hFile, "Group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "' does not exist" & @CRLF)
                                    ElseIf @error = 2 Then
                                        _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' does not exist" & @CRLF)
                                    ElseIf @error = 3 Then
                                        _FileWriteLog($hFile, "User '" & $aSamAccountName[$x][2] & "' is not a member of group '" & StringMid($sRemoveGroup,4,StringInStr($sRemoveGroup,',')-4) & "'" & @CRLF)
                                    Else
                                        _FileWriteLog($hFile, "Return code '" & @error & "' from Active Directory" & @CRLF)
                                    EndIf
                                EndIf
                            EndIf
                        EndIf
                    EndIf
                EndIf
            Next
        EndIf
    Next
EndFunc   ;==>FindADInfo

Hi

 

I need some help. I search for a group in a list of groups for AD users. For an exampel in 1 our site I'm looking for a group containing this "MailUsers". We have for that site groups like this "MailUsers_1", "MailUsers_2", "MailUsers_3" ect until _8. In the above code it works for "MailUsers_1 to 8", but if I on another site search for "M_ALL", groups like this "M_ALL_PT" is also found. Is there a small trix that can accomplish my request? Do I need to put all the groups I want to search for in an array?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
careca

Maybe you could get the string count, and only retrieve results with the same count.

"M_ALL" 5 chars

"M_ALL_PT" if <> 5 chars ignore.

something along these lines.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
Valnurat

Yes, that could be a solution.

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Were do you do the search in your script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat
If StringInStr($aUserGroups[$y], $aAllMailSites[$i][2],1) Then
    $bMailGroup = True
    Local $sRemoveGroup = $aUserGroups[_ArraySearch($aUserGroups,$aAllMailSites[$i][2],0,0,0,1,1)]
 EndIf

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

For your requirement only a regular expressions comes to my mind.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
×