Valnurat

Little advice

6 posts in this topic

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



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.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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

Share this post


Link to post
Share on other sites

Yes, that could be a solution.

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Were do you do the search in your script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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
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

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake