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

Au3Record.exe

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

    • Trisha
      By Trisha
      I tried (using AutoIt) to automate a scenario where i  have to open IE with specific URL on my extranet(Xen Desktop or Citrix ) ,from there i need to download  file and then through WinSCP; I  have to move that file to another location that can be access from my Local system using VMWare.
      I did as far as the above step. Now i want to navigate from my extranet to my local desktop system. But i am not able to move  from there.Mouse click is also not working.Please find the below screenshot highlighted in YELLOW.
       


    • bbk4163
      By bbk4163
      Hi, 
      I am getting "array variable has incorrect number of subscripts dimension range exceeded" error while executing exe. Not sure what is wrong here. 
      #include <MsgBoxConstants.au3> SelectWindowBasedOnTitle() Func SelectWindowBasedOnTitle()     $winList = WinList()     $wTitle = CheckWindows($winList)    IF $wTitle == "Choose File to Upload" Then             IE()    ElseIf $wTitle == "Open" Then             Chrome()    Else             FireFox()    EndIf EndFunc Func CheckWindows($aArray)     For $i = 1 To Ubound($aArray) - 1         If WinActive($aArray[$i][1]) Then $wTitle= $aArray[$i][0] ;MsgBox(0, "Window Check", $aArray[$i][0] & " is active.")     Next     Return $wTitle EndFunc Func Example()     $wText = WinGetText("[ACTIVE]") EndFunc Func IE()     ControlFocus("Choose File to Upload","","Edit1")     ControlSetText("Choose File to Upload","","Edit1",$CmdLine[1])     ControlClick("Choose File to Upload","","Button1") EndFunc Func Chrome()     ControlFocus("Open","","Edit1")     ControlSetText("Open","","Edit1",$CmdLine[1])     ControlClick("Open","","Button1") EndFunc Func FireFox()     ControlFocus("File Upload","","Edit1")     ControlSetText("File Upload","","Edit1",$CmdLine[1])     ControlClick("File Upload","","Button1") EndFunc  
    • TheWizEd
      By TheWizEd
      How do I work with 2D arrays.  I've tried this but get errors.
      Local $aTest[4][4] = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
      ;$aTest[0][] = [10,11,12]  ; Error at []
      Local $sTest = ""
      For $i = 0 To UBound($aTest)-1
        Local $aExtract = _ArrayExtract($aTest,$i,$i)
        $sTest = $sTest & MyTest($aExtract)
      Next
      Func MyTest($aTemp)
        _ArrayDisplay($aTemp)
        ; Error at    v $aTemp
        Return String($aTemp[0]) & " - " & String($aTemp[1]) & " - " & String($aTemp[2]) & @CRLF
      EndFunc
       
       
    • Valnurat
      By Valnurat
      Hi.
      If I use this code:
       
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $sServiceTAG = "9S1Y3J2" Local $oIE = _IECreate("http://www.dell.com/support/home/uk/en/ukbsdt1/product-support/servicetag/" & $sServiceTAG & "/warranty?ref=captchasuccess",Default,0,0) _IELoadWait($oIE) Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If StringStripWS($oTd.innertext, 7) = "NBD ProSupport" Then $sShipdate = StringStripWS($oTd.NextElementSibling.InnerText, 7) ExitLoop EndIf Next _IEQuit($oIE) MsgBox($MB_SYSTEMMODAL, "Warranty", $sShipdate) My messagebox is empty, but if I use the link first:
      http://www.dell.com/support/home/uk/en/ukbsdt1/product-support/servicetag/9S1Y3J2/warranty?ref=captchasuccess
      and then use my code I get results.
      Can someone help so I don't need to use the link first.
    • Valnurat
      By Valnurat
      Hi.
      I have this:
      november 08, 2015
      How can I convert it to:
      08/03/2015
      I don't see any convert option from month name to a number.
      Thank  you