Jump to content

Active Directory UDF (II)


Go to solution Solved by water,

Recommended Posts

Posted

:)

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 9 months later...
Posted (edited)

Hello,

To begin with I have been using the UDF for several years, it is great.

However, I have two problems:

1- See the screenshot above, it seems that there is a bad recognition when the names include a -

Everything that is in the OU "Et_2" is found by mistake in the OU "Et_-2".


2- I also have names with spaces. I saw the remark on this subject "If an OU contains spaces the sorting is wrong and might lead to problems in further processing.
Please have a look at http://www.autoitscript.com/forum/topic/106163-active-directory-udf/page__view__findpost__p__943892 "

But I admit that I did not quite understand the solution that must be put in place to correct this, can you give me more specific information?

Thank you in advance for your help.

Bug AD et GAIA.png

Edited by mprudhomme
Posted

I have taken and added the modifications made by trancexx (they are quite old and I'm sure the Array-functions have evolved over time).
You get the array and then the function displays the empty GUI. If the content of the array is correct, you can remove the lines makred with ("; <== Remove if the Treeview should be generated") in function _AD_GetOUTreeView.

  Reveal hidden contents

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Thank you for your reply, but unfortunately I cannot solve my problem :-(.
I admit that I have trouble understanding the modifications that must be made and in particular the use of "_AD_Example_GetOUTreeView" and "_AD_GetOUTreeView" which lose me because I do not use them in my program.

However, I copied your modifications so as not to use "_ArraySort" but rather "_ArraySortEX" and I have the same result.

My problem is indeed with the _ArraySort in the _AD_GetAllOUs function of the AD.au3 file.

In my code I run the command below to recreate a Treeview from my AD.
_AD_GetAllOUs ('OU = Computers, OU = distinguishedName ..., "\")

Below are different captures. The one without the _ArraySort is correct except that it is not sorted alphabetically like in the AD tree.

 

Do you have any additional solution to help me or it is a problem on my end that I cannot understand the use of your changes?

Thanks again for your help

TreeView AD.png

Posted

I will need to do some testing. As I do not have OUs with dashes or spaces in our AD (and as I'm just an ordinary user which can't modify our AD) I need to create the array by hand. Then I will try to find out what I did wrong when implementing the solution by trancexx or which change in the Array UDF since then makes her solution work no longer 🤔

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

I had a look at the function and did some tests. I then realized that the whole sorting thing isn't working.
I need to rewrite the function so it uses a multicolumn sort algorithm.
Please stay tuned but don't hold your breath ;)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

:D

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 2 weeks later...
Posted

The following (first version) of a function pads the subitems of a cell to a specified length so sorting returns the correct order.
Could you please run the example script (if you like you can add more of your data entries) and check if you get the desired result?

#include <Array.au3>
#include <debug.au3>

;----- Test Data
Local $aOUs[14][2]
$aOUs[1][0] = "01300_TEST\Ordinateurs"
$aOUs[1][1] = "OU=01300_TEST,OU=Ordinateurs,DC=company,DC=COM"
$aOUs[2][0] = "01300_TEST\Ordinateurs\Administratif"
$aOUs[2][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Administratif,DC=company,DC=COM"
$aOUs[3][0] = "01300_TEST\Ordinateurs\Pedagogique"
$aOUs[3][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=company,DC=COM"
$aOUs[4][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat_A"
$aOUs[4][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=Bat_A,DC=company,DC=COM"
$aOUs[5][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat_A\ET_-2"
$aOUs[5][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=Bat_A,DC=ET_-2,DC=company,DC=COM"
$aOUs[6][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat_A\ET_-2\Salle_02moins"
$aOUs[6][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=Bat_A,DC=ET_-2,DC=Salle_02moins,DC=company,DC=COM"
$aOUs[7][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat_A\ET_1"
$aOUs[7][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=Bat_A,DC=ET_1,DC=company,DC=COM"
$aOUs[8][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat_A\ET_1\Salle_01"
$aOUs[8][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=Bat_A,DC=ET_1,DC=Salle_01,DC=company,DC=COM"
$aOUs[9][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat_A\ET_1\Salle_02"
$aOUs[9][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique,DC=Bat_A,DC=ET_1,DC=Salle_02,DC=company,DC=COM"
$aOUs[10][0] = "01300_TEST\Ordinateurs\Pedagogique 2019"
$aOUs[10][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique 2019,DC=company,DC=COM"
$aOUs[11][0] = "01300_TEST\Ordinateurs\Pedagogique 2019\Bat_B"
$aOUs[11][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique 2019,DC=Bat_B,DC=company,DC=COM"
$aOUs[12][0] = "01300_TEST\Ordinateurs\Pedagogique 2019\Bat_B\ET_2"
$aOUs[12][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique 2019,DC=Bat_B,DC=ET_2,DC=company,DC=COM"
$aOUs[13][0] = "01300_TEST\Ordinateurs\Pedagogique 2019\Bat_B\ET_2\Salle_20"
$aOUs[13][1] = "OU=01300_TEST,OU=Ordinateurs,OU=Pedagogique 2019,DC=Bat_B,DC=ET_2,DC=Salle_20,DC=company,DC=COM"
;-----

_ExtendCells($aOUs)
_ArraySort($aOUs, 0, 0, 0, 0)
_DebugArrayDisplay($aOUs)
Exit

Func _ExtendCells(ByRef $aArray, $iStartRow = 0, $iColumn = 0, $sSeparator = "\", $iLength = 50)

    Local $aTemp, $sTemp, $iSubtract = 0, $sPadString = StringFormat("%" & $iLength & "s", " ")

    ; Pad the substrings of the cells of the specified column to the specified length
    If UBound($aArray, 0) = 1 Then ; 1D array
        ; Insert code for a 1D array here
    Else
        If $iStartRow = 0 Then $iSubtract = 1
        For $i = $iStartRow To UBound($aArray, 1) - $iSubtract
            $aTemp = StringSplit($aArray[$i][$iColumn], $sSeparator)
            If @error = 0 Then
                For $j = 1 To UBound($aTemp, 1) - 1
                    $sTemp = StringLeft($aTemp[$j] & $sPadString, $iLength)
                    $aArray[$i][$iColumn] = ($j > 1) ? ($aArray[$i][$iColumn] & $sSeparator & $sTemp) : ($sTemp)
                Next
            EndIf
        Next
    EndIf

    ; Sort the array on the padded column
    _ArraySort($aArray, 0, $iStartRow, 0, $iColumn)

    ; Remove the padding characters
    If UBound($aArray, 0) = 1 Then ; 1D array
        ; Insert code for a 1D array here
    Else
        If $iStartRow = 0 Then $iSubtract = 1
        For $i = $iStartRow To UBound($aArray, 1) - $iSubtract
            While 1
                $aArray[$i][$iColumn] = StringReplace($aArray[$i][$iColumn], " " & $sSeparator, $sSeparator)
                If @extended = 0 Then ExitLoop
            WEnd
        Next
    EndIf

EndFunc   ;==>_ExtendCells

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Second version (fixing some problems with first version):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -w 8
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <debug.au3>

;----- Test Data
Global $aOUs[16][2] = [[15, 2]]
$aOUs[01][0] = "01300_TEST\Ordinateurs"
$aOUs[02][0] = "01300_TEST\Ordinateurs\Administratif"
$aOUs[03][0] = "01300_TEST\Ordinateurs\Pedagogique"
$aOUs[04][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A"
$aOUs[05][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_-2"
$aOUs[06][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_-2\Salle_02moins"
$aOUs[07][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_1"
$aOUs[08][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_1\Salle_01"
$aOUs[09][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_1\Salle_02"
$aOUs[10][0] = "01300_TEST\Ordinateurs\Pedagogique 2019"
$aOUs[11][0] = "01300_TEST\Ordinateurs\Pedagogique 2019\Bat_B"
$aOUs[12][0] = "01300_TEST\Ordinateurs\Pedagogique 2019\Bat_B\ET_2"
$aOUs[13][0] = "01300_TEST\Ordinateurs\Pedagogique 2019\Bat_B\ET_2\Salle_20"
$aOUs[14][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_-1"
$aOUs[15][0] = "01300_TEST\Ordinateurs\Pedagogique\Bat A\ET_-1\Salle_10"
;-----

_ExtendCells($aOUs, 1)
Exit

Func _ExtendCells(ByRef $aArray, $iStartRow = 0, $iColumn = 0, $sUsedSeparator = "\", $sSortSeparator = "|", $sPaddingCharacter = " ", $iLength = 50)

    Local $aTemp, $sTemp, $sPadString = StringFormat("%" & $iLength & "s", $sPaddingCharacter)

    ; Pad the substrings of the cells of the specified column to the specified length
    If UBound($aArray, 0) = 1 Then ; 1D array
        ; Insert code for a 1D array here
    Else
        For $i = $iStartRow To UBound($aArray, 1) - 1
            $aArray[$i][$iColumn] = Stringreplace($aArray[$i][$iColumn], $sUsedSeparator, $sSortSeparator)
            $aTemp = StringSplit($aArray[$i][$iColumn], $sSortSeparator, $STR_NOCOUNT)
            If @error = 0 Then
                For $j = 0 To UBound($aTemp, 1) - 1
                    $sTemp = StringLeft($aTemp[$j] & $sPadString, $iLength - 1)
                    $aArray[$i][$iColumn] = ($j = 0) ? ($sTemp & $sSortSeparator) : ($aArray[$i][$iColumn] & $sTemp & $sSortSeparator)
                Next
            EndIf
        Next
    EndIf

    ; Sort the array on the padded column
    _DebugArrayDisplay($aOUs, "Before sorting")
    _ArraySort($aArray, 0, $iStartRow, 0, $iColumn)
    _DebugArrayDisplay($aOUs, "After sorting")

    ; Remove the padding characters
    If UBound($aArray, 0) = 1 Then ; 1D array
        ; Insert code for a 1D array here
    Else
        For $i = $iStartRow To UBound($aArray, 1) - 1
            If StringRight($aArray[$i][$iColumn], 1) = $sSortSeparator Then $aArray[$i][$iColumn] = StringTrimRight($aArray[$i][$iColumn], 1) ; Remove rightmost separator character
            $aArray[$i][$iColumn] = StringReplace($aArray[$i][$iColumn], $sPaddingCharacter & $sSortSeparator, $sUsedSeparator)
            While 1
                $aArray[$i][$iColumn] = StringReplace($aArray[$i][$iColumn], $sPaddingCharacter & $sUsedSeparator, $sUsedSeparator)
                If @extended = 0 Then ExitLoop
            WEnd
        Next
    EndIf
    _DebugArrayDisplay($aOUs, "After sorting and removing padding characters")
EndFunc   ;==>_ExtendCells

What do you think? Does it work for you?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Hi,

First of all thank you for researching this problem and sorry for the delay in responding.

I encountered problems with the first version but the second seems to work perfectly!

To make sure I didn't make any mistakes, here's what I did to integrate the changes into my project:
- In my au3 file I added <Degug.au3>
- In the AD.au3 file
          - In the "Func _AD_GetAllOUs" function I replaced "ArraySort ($aOUs)" by "_ExtendCells ($aOUs, 1)"
          - In this same file I copied the function "_ExtendCells"
          - In this same file I had to declare the variable $aOUs (global $aOUs) otherwise I have a use message before declaration

Are the changes I made correct or do I have to do it differently?

 

Really a HUGE thank you for fixing this problem.

Marcel

Posted (edited)

Looks good!

I will add the modification to the AD UDF and hope to release a new version (1.5.2.1) quite soon.

Edit:
- In my au3 file I added <Degug.au3> No longer needed with the latest version of the UDF
- In the AD.au3 file
    - In the "Func _AD_GetAllOUs" function I replaced "ArraySort ($aOUs)" by "_ExtendCells ($aOUs, 1)" No longer needed with the latest version of the UDF
    - In this same file I copied the function "_ExtendCells" No longer needed with the latest version of the UDF
    - In this same file I had to declare the variable $aOUs (global $aOUs) otherwise I have a use message before declaration. No longer needed with the latest version of the UDF

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Thanks a lot for your feedback :) 
Glad you like the UDF and the support :D 

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 3 months later...
Posted

Hello,

great library and work very well !

With the function _AD_GetAllOUs I have strange backslash at the end of line on some OU :

ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\Angellier
OU=Angellier,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\Angellier\B1619(tbi)\
OU=B1619(tbi),OU=Angellier,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\ArtsCulture
OU=ArtsCulture,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\ArtsCulture\B2451\
OU=B2451,OU=ArtsCulture,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\CIREL
OU=CIREL,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\CIREL\B3328\
OU=B3328,OU=CIREL,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
ULilleRessources\DSI\DSISHS\Pont_de_Bois\Pedagogie\TICE\DEDIEES\CIREL\B3332\
OU=B3332,OU=CIREL,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr

I remove them in my code but it's normal ?

Posted

How do you call _AD_GetAllOUs (which parameters do you pass)?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Hello,

I call it with
 

Local $root_ou = ""

 _AD_GetAllOUs($root_ou)

or

Local $root_ou = "OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr"

 _AD_GetAllOUs($root_ou)

I have the same result with backslash on certain OU

Maybe is the start of parenthesis ?

OU=B1619(tbi),OU=Angellier,OU=DEDIEES,OU=TICE,OU=Pedagogie,OU=Pont_de_Bois,OU=DSISHS,OU=DSI,OU=ULilleRessources,DC=ad,DC=univ-lille,DC=fr
Posted

Good point!

I will do some checks and come back later :)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

I have notice other strange thing with version 1.5.2.1 (before I use the 1.4.14.0) for the first column of array :

- I have to remove extra space otherwise Stringlen function return incorrect number of character

- when I use _ArraySearch function I must set the $iCompare parameter to 1 otherwise the function found nothing

That's all for the moment. 😅

Thank you again and good luck.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...