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.

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
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 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
water

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

    • DynamicRookie
      By DynamicRookie
      Hey there!
       
      Is there a way to detect movement only for 1 specific window?

      HWnd is not really working, it still detects movement in all the windows within the region

      This is my script:
       
      ;Checksum actual HotKeySet("{f2}", 'exit_') MsgBox(0, '', '0') Beep(500, 2000) $Hwnd = WinActive('') while 1 $Checksum = PixelChecksum(211, 650, 1094, 914, 1, $Hwnd) If PixelChecksum(211, 650, 1094, 914, 1, $Hwnd) <> $Checksum Then For $i = 1 To 100 Beep(1000, 50) Next MsgBox(0, '', 'New message!', 1) EndIf WEnd Func exit_() Beep(500, 1000) Exit 0 EndFunc I just want to check whenever a message comes because the app i use doesn't give notifications properly.

      Any help is really appreciated!
    • PramodR
      By PramodR
      Can you please see whats wrong im doing in the below code? i can read few registry entry but not all for eg, i am able to get value of "Shell" Key from the registry path  but not AutoAdminLogon which has the value of "1", is there any change i have to do to read numeric values?
       Global  $shello = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Shell" )
       ConsoleWrite("This is Hello"& $shello)
      above command returns proper value , but same command with AutoAdminLogon returns null as shown in below ? infact registry has the value of 1.
       Global  $shello = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AutoAdminLogon" )
       ConsoleWrite("This is Hello"& $shello)
    • Eminence
      By Eminence
      Hello,
      I've been searching on how to select the first row in my database which includes a time column based on the latest start_time date for today's date.
      This is my current code:
      Local $iCurrentDate = _Now() Local $sqlHandle = _dbOpen($sDbPath) Local $aResult, $iRows, $iCols _SQLite_GetTable2d($sqlHandle, "SELECT start_time FROM " & $srawDb & " ORDER BY datetime(start_time) DESC LIMIT 1", $aResult, $iRows, $iCols) _ArrayDisplay($aResult) _dbClose($sDbpath) What it does is it gets the first row entry in the database however it does not select the latest start_time entry in the database, it always select the first row. I've tried changing DESC to ASC to see if that will do it but the issue still remains. Any thoughts on this? Thanks in advance.
       
      *EDIT
      The date format in the database is by MM/DD/YYYY HH:MM:SS.
    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • TrashBoat
      By TrashBoat
      hey i would like to know if its possible to take a string like this
      $string = "onethousandninehundredeightyfive" and convert it into:
      $string = "one thousand nine hundred eighty five" i have something going on here but its no use
      $string = "onethousandninehundredeightyfive" Global $array[9] = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] Global $array1[19] = ['onethousand', 'twothousand', 'threethousand', 'fourthousand', 'fivethousand', 'sixthousand', 'seventhousand', 'eightthousand', 'ninethousand','tenthousand','hundred', 'twohundred', 'threehundred', 'fourhundred', 'fivehundred', 'sixhundred', 'sevenhundred', 'eighthundred', 'ninehundred'] MsgBox(0, 0, AddSpaces($string)) Func AddSpaces($string) Local $finalStr $length = StringLen($string) For $x = 0 To $length Local $trim = StringTrimRight($string, $x) For $h = 0 To 18 If $trim = $array1[$h] Then $finalStr = $finalStr & " " & $trim $string = StringTrimLeft($string, $h) $length = StringLen($string) EndIf Next For $z = 0 To 8 If $trim = $array[$z] Then $finalStr = $finalStr & " " & $trim $string = StringTrimLeft($string, $z) $length = StringLen($string) EndIf Next Next Return $finalStr EndFunc ;==>AddSpaces  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.