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.

MirrorDir - Synchronize/Backup/Mirror Folders

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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • yasha
      By yasha
      i want am trying to select a nimber to run a program and then select where to save the excel result at before hand
      the problem is that it does not save in the folder i want but the folder before any solutions
      #.................
      $sFolder = ""
          ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
          Local Const $sMessage = "Select a folder"
          ; Display an open dialog to select a file.
          $sFileSelectFolder = FileSelectFolder($sMessage, $sFolder)
          If @error Then
              ; Display the error message.
              MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
          Else
              ; Display the selected folder.
              MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
          EndIf
      .......
      ........
      $oExcel = ObjCreate("Excel.Application")                   ; Create an Excel Object
      $oExcel.Visible = 1                                        ; Let Excel show itself
      $oExcel.Workbooks.Open("J:\OPS\OPS_Share\Planners\2 - Weekly Reports\Auto download\"& $YY & $MM & $DD & " ORDER.xls",0)
      $oExcel.ActiveWorkbook.Saveas ( $sFileSelectFolder,""& $YY & $MM & $DD & " ORDER.xlsx", 1)
      $oExcel.ActiveWorkBook.Close
      $oExcel.Quit
      i only want to save it as ddmmyy order inside documents but it saves in libraries as documents ddmmyy order.
    • vynce1982
      By vynce1982
      I am trying to make a simple installer script for my understanding.  I would just like to understand how to deal with multiple possible windows. In the case of installing VLC, I might get a window saying VLC is already installed. I have also tried a switch with no luck.  I would just like to understand some methods for dealing with the possible existence of unexpected windows. 
       
      ;INSTALL VLC VIEWER
      Run(@ScriptDir & '\bin\VLCViewer_2.2.4_3.EXE')
      AutoItSetOption('MouseCoordMode', 0)
      sleep(4000)
      WinWait("VLC Viewer 2.2.4")

           ; this window will pop up if vlc is already installed
          If WinExists( "VLC Viewer 2.2.4", "VLC 2.2.4 Already Installed") Then
                ConsoleWrite ("already installed")
                WinActivate ('VLC Viewer 2.2.4','Already Installed')
                MouseClick ('primary', 93, 83, 1, 0)
                
          EndIf
       
            ; this window will pop up if installer finishes sucessfully
           If WinExists( "VLC Viewer 2.2.4", "VLC Viewer 2.2.4 Installed") Then 
                ConsoleWrite ("already installed")
                WinActivate ('VLC Viewer 2.2.4','VlC Installed')
                MouseClick ('primary', 93, 83, 1, 0)
         EndIf

       
       
       
    • TrashBoat
      By TrashBoat
      After i create my GUI i cant set the color anymore.  help?
      $hBarGUI1 = GUICreate("", 50, 1, 91, 188, 0x80000000, 0x08000080) $g = GUICtrlCreateLabel("", 1, 1, 1, 1) GUICtrlSetBkColor(-1, $color) GUISetBkColor($color, $hBarGUI1) WinSetTrans($hBarGUI1, '', 0) WinSetState($hBarGUI1, '', @SW_SHOWNOACTIVATE) WinMove($hBarGUI1, '', -1, -1) WinSetTrans($hBarGUI1, '', 254) WinSetOnTop($hBarGUI1, "", 1) I see that my problem has to do something with WinSetState but have no clue how to fix it already tried to set it to @SW_UNLOCK and @SW_SHOWNORMAL.
      @swa
×