Jump to content

playing with arrays and lists


31290
 Share

Recommended Posts

Lets display the array when it hasn't enough elements:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")

_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
if $aTemp[0] < 4 Then _ArrayDisplay($aTemp)
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Here's the latest output. 

Did you see my last edit?

Closing the window by the X displays next result. And so on until 507 :) I've exited the script before lol

 

array.jpg

Edited by 31290
more info

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

If this is a valid user, how should the script extract Site and Country?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

What do you mean by "valid"?

I'm not sure having well understand the question but If I output the array to a file, using _AD_GetObjectsInOU("", "(ANR=" & $currentUser & ")", 2, "sAMAccountName,distinguishedName,displayname", "displayname"), I have this:

307|3|
USERID|CN=XXXX,OU=Users,OU=SITE,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX|NAME, FIRST NAME
XXXX|CN=XXXX,OU=Users,OU=XXXX,OU=Mexico,OU=LA,DC=XXXX,DC=XXXX|XXXX XXXX
XXXX|CN=XXXX,OU=Users,OU=XXXX,OU=Argentina,OU=LA,DC=XXXX,DC=XXXX|XXXX XXXX

So site and country are comma separated but within the same row.

 

 

Edited by 31290
forgot something

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

I mean the script works fine when I take "CN=XXXX,OU=Users,OU=SITE,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX" and split it into pieces to display Site and Country. This example is being split into 4 pieces.
When the script crashes the distinguished name is split into only 3 pieces and when the script tries to access "piece" 4 it crashes.
So in this case the distinguished name looks different.
Does this distinguished name point to a user or a group or an OU or something different?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Does this distinguished name point to a user or a group or an OU or something different?

In this case, the distinguished name points to a user with all information about it's location.

CN="UserID",OU=Users,OU=SITE,OU=COUNTRY,OU=WORLDREGION,DC=XXXX,DC=XXXX

For a group, it will be : CN="GroupName",OU=Groups,OU=SITE,OU=COUNTRY,OU=EU,DC=XXXX,DC=XXXX

Hope this helps

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

Strange, your examples give the correct number of "pieces".
Let's limit the result to users only and check if the probelm goes away.
 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"
Global $aResult = _AD_GetObjectsInOU("", "(&(objectcategory=person)(objectclass=user)(ANR=" & $Username & "))", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
_AD_Close()
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
if $aTemp[0] < 4 Then ConsoleWrite($aResult[$i][2] & @CRLF)
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I've attached the results.

But if I close it, I got:

(41) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & ^ ERROR

That's really strange.

array0.jpg

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

I have modified the script above so we get the failing distinguished name written to the Console.
Can you please send me the Console output using the forums PM (private message) feature. Confident data can be masked using "***" but I need the structure of the FQDN.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here we have a version of the script that only includes certain OUs which can be specified in an array (or read from an ini file). Table $aInclude needs to be modified by you.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $resources & "\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"
Global $aInclude[] = ["OU=EU,DC=XXXX,DC=XXXX", "OU=NA,DC=XXXX,DC=XXXX", "OU=LA,DC=XXXX,DC=XXXX", "OU=LA,DC=XXXX,DC=XXXX"] ; Only the OUs specified in this array will be processed
Global $iInclude = UBound($aInclude, 1) - 1, $bFound

$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
    MsgBox(0, "", "NO GO") ; Ad connection results
Else
    MsgBox(0, "", "GO") ; Ad connection results
EndIf

$sUser = "martin"
Global $aResult = _AD_GetObjectsInOU("", "(&(objectcategory=person)(objectclass=user)(ANR=" & $sUser & "))", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
_AD_Close()
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $bFound = False
    For $i = 0 To $iInclude
        If StringRight($sUser, StringLen($aInclude[$i])) = $aInclude[$i] Then
            $bFound = True
            ExitLoop
        EndIf
    Next
    If $bFound Then
        $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
        $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
        GUICtrlCreateListViewItem($sTemp, $g_idListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
    EndIf
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ok, I've made necessary changes but for a very common name, nothing appears. 

For mine, the GUI List displays but is empty.

Nothing to report in the Scite Console as well.

ad3.jpg

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

My bad. Line

If StringRight($sUser, StringLen($aInclude[$i])) = $aInclude[$i] Then

should be

If StringRight($aResult[$i][2], StringLen($aInclude[$i])) = $aInclude[$i] Then

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I hope this version now will be free of bugs ;)

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $resources & "\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"
Global $aInclude[] = ["OU=EU,DC=XXXX,DC=XXXX", "OU=NA,DC=XXXX,DC=XXXX", "OU=LA,DC=XXXX,DC=XXXX", "OU=LA,DC=XXXX,DC=XXXX"] ; Only the OUs specified in this array will be processed
Global $iInclude = UBound($aInclude, 1) - 1, $bFound

$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
    MsgBox(0, "", "NO GO") ; Ad connection results
Else
    MsgBox(0, "", "GO") ; Ad connection results
EndIf

$sUser = "martin"
Global $aResult = _AD_GetObjectsInOU("", "(&(objectcategory=person)(objectclass=user)(ANR=" & $sUser & "))", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
_AD_Close()
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $bFound = False
    For $j = 0 To $iInclude
        If StringRight($aResult[$i][2], StringLen($aInclude[$j])) = $aInclude[$j] Then
            $bFound = True
            ExitLoop
        EndIf
    Next
    If $bFound Then
        $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
        $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
        GUICtrlCreateListViewItem($sTemp, $g_idListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
    EndIf
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water!

This is working perfectly! No more bugs or so, that is so cool! Having excluded bad OU made this works.

How can I return the favor back for you excellent input? :)

Just a very quick one for you, the last, I promise ^^

Do you know how to make a result double clickable in order to display more information about the selected user?

EDIT: 

I've added this: 

Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
                 Case $NM_DBLCLK ; An item was double clicked
                    Msgbox(0, "", $aResult[$i][0])
EndSwitch

When launching and double clicking on an item, I got  

"C:\Users\h74033\Downloads\GUICtrlCreateListView.au3" (77) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Msgbox(0, "", $aResult[$i][0])
Msgbox(0, "", ^ ERROR

Whereas replacing $aResult[$i][0] by "Test" is working fine. In fact I want to put the "User ID" is a variable for future operations ^^

 

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

I suggest to create a Context Menu for the Listview and use right click to display a menu of function. For an example check my AD tool ADCU.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi Water, 

I took a look at your script but I'm not sure this will be the easiest way for me to do so. 

I need to find the way to get the User ID from the array but after some tests, I can't figure it out.

 

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

Something like this?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIListview.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <Math.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $resources & "\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"
Global $aInclude[] = ["OU=EU,DC=XXXX,DC=XXXX", "OU=NA,DC=XXXX,DC=XXXX", "OU=LA,DC=XXXX,DC=XXXX", "OU=LA,DC=XXXX,DC=XXXX"] ; Only the OUs specified in this array will be processed
Global $iInclude = UBound($aInclude, 1) - 1, $bFound, $sSelected, $aSelected

$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error Then Exit MsgBox(0, "", "NO GO") ; AD connection results

$sUser = "martin"
Global $aResult = _AD_GetObjectsInOU("", "(&(objectcategory=person)(objectclass=user)(ANR=" & $sUser & "))", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
; Context Menu
Global $hCM = GUICtrlCreateContextMenu($g_idListView)
Global $hCM_Detail = GUICtrlCreateMenuItem("Detail", $hCM)
Global $hCM_Delete = GUICtrlCreateMenuItem("Delete", $hCM)
Global $hCM_Copy = GUICtrlCreateMenuItem("Copy Group", $hCM)
For $i = 1 To $aResult[0][0]
    $bFound = False
    For $j = 0 To $iInclude
        If StringRight($aResult[$i][2], StringLen($aInclude[$j])) = $aInclude[$j] Then
            $bFound = True
            ExitLoop
        EndIf
    Next
    If $bFound Then
        $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
        $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
        GUICtrlCreateListViewItem($sTemp, $g_idListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
    EndIf
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _AD_Close()
            ExitLoop
        Case $hCM_Detail
            _GetObjectDetail($sSelected)
        Case $hCM_Delete
            MsgBox(0, "Info", "You would now remove group '" & $sSelected & "' from the user!")
        Case $hCM_Copy
            MsgBox(0, "Info", "You would now copy group '" & $sSelected & "' to the other user!")
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    ; Disable context menu when no listview item was selected
                    If $iItem = -1 Then
                        GUICtrlSetState($hCM_Detail, $GUI_DISABLE)
                        GUICtrlSetState($hCM_Delete, $GUI_DISABLE)
                        GUICtrlSetState($hCM_Copy, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($hCM_Detail, $GUI_ENABLE)
                        GUICtrlSetState($hCM_Delete, $GUI_ENABLE)
                        GUICtrlSetState($hCM_Copy, $GUI_ENABLE)
                        $aSelected = _GUICtrlListView_GetSelectedIndices($hWndListView, True)
                        If $aSelected[0] >= 1 Then $sSelected = _GUICtrlListView_GetItemText($hWndListView, $aSelected[1], 1)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

;-------------------------------
; Show all properties of a group
;-------------------------------
Func _GetObjectDetail($Object)

    Local $aProperties[1][1] = [[0]], $hButtonUser = -1
    $aProperties = _AD_GetObjectProperties($Object)
    If @error Or Not IsArray($aProperties) Then Return
    Local $sTitle = "Group: " & $sSelected
    _ArraySort($aProperties, 0, 1)
    Local $iWindowWidth = 400, $iWindowWidthNew
    Local $hGUI = GUICreate("Details for " & $sTitle, $iWindowWidth, @DesktopHeight - 100, 10, 10, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
    Local $hButtonEnd = GUICtrlCreateButton("Close", 2, @DesktopHeight - 128, 75, 23)
    Local $hButtonCopy = GUICtrlCreateButton("Copy", 80, @DesktopHeight - 128, 75, 23)
    Local $hListView = GUICtrlCreateListView("Property|Value", 2, 2, 396, @DesktopHeight - 140)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_BeginUpdate($hListView)
    ; Add items
    For $i = 1 To $aProperties[0][0]
        GUICtrlCreateListViewItem($aProperties[$i][0] & "|" & $aProperties[$i][1], $hListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7)
    Next
    GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 0, $LVSCW_AUTOSIZE_USEHEADER)
    GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 1, $LVSCW_AUTOSIZE_USEHEADER)
    _GUICtrlListView_EndUpdate($hListView)
    $iWindowWidthNew = _Min(@DesktopWidth, _GUICtrlListView_GetColumnWidth($hListView, 0) + _GUICtrlListView_GetColumnWidth($hListView, 1) + 35)
    WinMove($hGUI, "", 10, 10, $iWindowWidthNew)
    GUICtrlSetPos($hListView, 2, 2, 396 + $iWindowWidthNew - $iWindowWidth, @DesktopHeight - 140)
    GUISetState(@SW_SHOW)
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE, $hButtonEnd
                ExitLoop
            Case $hButtonCopy
                ClipPut(_ArrayToString($aProperties, @TAB))
                ToolTip("Copied!", Default, Default, "", 1)
                Sleep(2000)
                ToolTip("")
        EndSwitch
    WEnd
    GUIDelete()

EndFunc   ;==>_GetObjectDetail

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

That was easy :) I just had to copy a few lines from another script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...