Array durchsuchen und Zählen

  • Hallo Zusammen,

    vielleicht hat jemand von euch eine Lösung!
    Ich habe ein Array aus folgender Function!

    [autoit]


    $aObjects = _AD_GetObjectsInOU("OU=User,OU="&$aOUs[$x]&",DC=Domäne,DC=int", "(&(objectcategory=person)(objectclass=user)(mail=*)(userAccountControl=512))", 2, "sAMAccountName,mail,company")

    [/autoit]

    im array stehen jetzt die werte "sAMAccountName,mail,company"
    unter Company steht jetzt für jeden User ein eintrag Beispiel wie folgt:

    [autoit]

    user1 Firma1
    user2 Firma1
    user3 Firma1
    user4 Firma2
    user5 Firma2
    user6 Firma1
    user7 Firma3
    user8 Firma3
    user9 Firma2

    [/autoit]


    wie kann ich jetzt die company einträge zählen?
    als ergebnis sollte herauskommen:
    Firma1 = 4
    Firma2 = 3
    Firma3 = 2

    Gruß gmmg

    5 Mal editiert, zuletzt von gmmg (13. April 2012 um 16:36) aus folgendem Grund: erweiterte lösung benötigt :)

  • Hallo gmmg,

    ich würde es so lösen:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    dim $aObjects[9][2]

    [/autoit] [autoit][/autoit] [autoit]

    for $i = 1 to 9
    $aObjects[$i-1][0] = "User" & $i
    Next
    for $i = 1 to 3
    $aObjects[$i-1][1] = "Firma1"
    Next
    for $i = 4 to 5
    $aObjects[$i-1][1] = "Firma2"
    Next
    for $i = 7 to 8
    $aObjects[$i-1][1] = "Firma3"
    Next
    $aObjects[5][1] = "Firma1"
    $aObjects[8][1] = "Firma2"
    _ArraySort($aObjects,0,0,0,1)
    _ArrayDisplay($aObjects)
    $sVar = ""
    $icount = 0

    [/autoit] [autoit][/autoit] [autoit]

    for $i = 0 to UBound($aObjects) -1
    if $sVar <> $aObjects[$i][1] Then
    if $icount > 0 Then ConsoleWrite($sVar & " " & $icount & @CRLF)
    $sVar = $aObjects[$i][1]
    $icount = 1
    Else
    $icount += 1
    EndIf
    Next
    if $icount > 0 Then ConsoleWrite($sVar & " " & $icount & @CRLF)

    [/autoit]

    Hier noch eine 2. Möglichkeit:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    Dim $aObjects[9][2]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To 9
    $aObjects[$i - 1][0] = "User" & $i
    Next
    For $i = 1 To 3
    $aObjects[$i - 1][1] = "Firma1"
    Next
    For $i = 4 To 5
    $aObjects[$i - 1][1] = "Firma2"
    Next
    For $i = 7 To 8
    $aObjects[$i - 1][1] = "Firma3"
    Next
    $aObjects[5][1] = "Firma1"
    $aObjects[8][1] = "Firma2"
    _ArraySort($aObjects, 0, 0, 0, 1)
    _ArrayDisplay($aObjects)
    $aCompanies = _ArrayUnique($aObjects, 2);alle Firmen in ein Array
    _ArrayDisplay($aCompanies)
    $sVar = ""

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $aCompanies[0]
    $aTemp = _ArrayFindAll($aObjects, $aCompanies[$i], 0, 0, 0, 0, 1);alle Indices der Firma in ein Array
    ;_ArrayDisplay($aTemp)
    ConsoleWrite($aCompanies[$i] & " " & UBound($aTemp) & @CRLF)
    Next

    [/autoit]



    mfg autoBert

    Einmal editiert, zuletzt von autoBert (2. Februar 2011 um 19:57)

  • Wenn das ganze in Stringform ist, dann machst du das am besten mit StringRegExp. Wenn du mal ein Beispiel für einen User- und Firmennamen gibst kann ich dir dabei auch helfen ;).
    Also erst die Firmen mit SttringRegExp herausfiltern und dann mit StringReplace o.Ä. jeweils die Einträge zählen.

  • Hallo,

    danke für die Infos!!!
    werd das dann gleich mal testen! :)

    name22 das ist ne gute frage, muss ich gleich mal nachsehen, wie er das array erstellt!
    mit der AD Funktion:

    [autoit]


    $aObjects = _AD_GetObjectsInOU("OU=User,OU="&$aOUs[$x]&",DC=Domäne,DC=int", "(&(objectcategory=person)(objectclass=user)(mail=*)(userAccountControl=512))", 2, "sAMAccountName,mail,company")

    [/autoit]


    wird ein Array mit 3 spalten erstellt, also nicht als string

    [autoit]


    $aObjects[$i][0] = username
    $aObjects[$i][1] = email
    $aObjects[$i][2] = company

    [/autoit]

    gruß gmmg

    4 Mal editiert, zuletzt von gmmg (2. Februar 2011 um 20:27)

  • danke!!!

    lasse mir das ergebnis gerade in ein array schreiben und bekomme einen fehler wenn $aObjects[$i][2] leer ist!

    [autoit]


    _ArraySort($aObjects,0,0,0,1)
    ;_ArrayDisplay($aObjects)
    $sVar = ""
    $icount = 0

    [/autoit][autoit][/autoit][autoit]

    for $i = 1 to UBound($aObjects) -1
    if $sVar <> $aObjects[$i][2] Then
    if $icount > 0 Then ConsoleWrite($sVar & " " & $icount & @CRLF)
    $sVar = $aObjects[$i][2]
    $icount = 1
    Else
    $icount += 1
    EndIf
    Next
    if $icount > 0 Then _ArrayAdd($avArray_1, $sVar & " " & $icount) ;ConsoleWrite($sVar & " " & $icount & @CRLF & "----------------")
    _ArrayDisplay($avArray_1)

    [/autoit][autoit][/autoit][autoit][/autoit]

    den fehler hab ich abgefangen!!!

    [autoit][/autoit][autoit][/autoit][autoit]

    For $x = 1 to $aOUs[0]
    ;MsgBox(0,"", $aOUs[$x])
    $aObjects = _AD_GetObjectsInOU("OU=User,OU="&$aOUs[$x]&",DC=domäne,DC=int", "(&(objectcategory=person)(objectclass=user)(mail=*)(userAccountControl=512))", 2, "sAMAccountName,mail,company")
    ;_ArrayDisplay($aObjects)

    [/autoit][autoit][/autoit][autoit]

    If @error > 0 Then
    ;MsgBox(64, "", "Nichts gefunden Error: " & @error)
    Else

    [/autoit][autoit][/autoit][autoit]

    ;---- zählen user in companys pro site
    _ArraySort($aObjects,0,0,0,1)
    ;_ArrayDisplay($aObjects)
    $sVar = ""
    $icount = 0

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 to UBound($aObjects) -1
    IF $aObjects[0][0] <> "" Then
    If $sVar <> $aObjects[$i][2] Then
    If $icount > 0 Then _ArrayAdd($avArray_1, $sVar & " " & $icount);if $icount > 0 Then ConsoleWrite($sVar & " " & $icount & @CRLF)
    $sVar = $aObjects[$i][2]
    $icount = 1
    Else
    $icount += 1
    EndIf
    EndIf
    Next
    If $icount > 0 Then _ArrayAdd($avArray_1, $sVar & " " & $icount) ;ConsoleWrite($sVar & " " & $icount & @CRLF & "----------------")
    _ArrayDisplay($avArray_1)
    ;--------------------------------------

    [/autoit]

    als ergebnis erhalte ich folgendes array:
    [1]|Firma1 10
    [2]|Firma2 1
    [3]|Firma1 135
    [4]|Firma3 1
    [5]|Firma1 27

    diese müssten jetzt zusammengezählt werden :)
    Firma1 = 172
    Firma2 = 1
    Firma3 = 1

    gruß gmmg

    Einmal editiert, zuletzt von gmmg (2. Februar 2011 um 21:09)

  • Hallo gmmg,

    ich habe aus dem 2. Lösungsvorschlag (siehe Post#2) eine func erstellt:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    Dim $aObjects[9][3]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To 9
    $aObjects[$i - 1][0] = "User" & $i
    $aObjects[$i - 1][1] = "noreply@nomailplease.con"
    Next
    For $i = 1 To 3
    $aObjects[$i - 1][2] = "Firma1"
    Next
    For $i = 4 To 5
    $aObjects[$i - 1][2] = "Firma2"
    Next
    For $i = 7 To 8
    $aObjects[$i - 1][2] = "Firma3"
    Next
    $aObjects[5][2] = "Firma1"
    $aObjects[8][2] = "Firma2"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Array = _GetUsers_Summary($aObjects)
    if not @error Then _ArrayDisplay($Array)

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetUsers_Summary(ByRef $aObjects)
    if not IsArray($aObjects) Then SetError(1,0,0)
    Local $aCompanies = _ArrayUnique($aObjects, 3)
    _ArraySort($aCompanies)
    Local $aResult[$aCompanies[0]][2]
    For $i = 1 To $aCompanies[0]
    $aResult[$i - 1][0] = $aCompanies[$i]
    Next
    For $i = 0 To UBound($aResult) - 1
    $aTemp = _ArrayFindAll($aObjects, $aResult[$i][0], 0, 0, 0, 0, 2)
    $aResult[$i][1] = UBound($aTemp)
    Next
    Return $aResult
    EndFunc ;==>_GetAD_Summary

    [/autoit]

    erwartet wird als Übergabe ein 2D-Array mit 3 Spalten Spalte 0 = User Spalte 2 = Firma. Zurückgegeben wird ein 2D-Array Spalte0 = Firma, Spalte 1 = Anzahl der User,

    mfg autoBert

  • autoBert

    bekomme beim ausführen eine fehlermeldung:

    Array variable subscript badly formatted.: Local $aResult[$aCompanies[0]][2]

    [autoit]


    Func _GetUsers_Summary(ByRef $aObjects)
    if not IsArray($aObjects) Then SetError(1,0,0)
    Local $aCompanies = _ArrayUnique($aObjects, 3)
    _ArraySort($aCompanies)
    _ArrayDisplay($aCompanies) ; bis hierhin funktioniert es (siehe ArrayDisplay.gif)
    Local $aResult[$aCompanies[0]][2] ; hier kommt der fehler
    For $i = 1 To $aCompanies[0]
    $aResult[$i - 1][0] = $aCompanies[$i]
    Next
    For $i = 0 To UBound($aResult) - 1
    $aTemp = _ArrayFindAll($aObjects, $aResult[$i][0], 0, 0, 0, 0, 2)
    $aResult[$i][1] = UBound($aTemp)
    Next
    Return $aResult
    EndFunc ;==>_GetAD_Summary

    [/autoit]


    finde aber den fehler nicht!!!

    leider sortiert _ArraySort nicht richtig, wenn aus irgendeinem grund im array der 3. wert fehlt!
    könnte man in diesen fall z.b. ein error als 3 wert einfügen?

    so funktioniert es nicht!

    [autoit]


    For $i = 1 to UBound($aObjects) -1
    ;MsgBox(0,"", $aObjects[$i][2])
    If $aObjects[$i][2] = "" Then _Array2DInsert($aObjects, $aObjects[$i][2], "kein Wert")
    Next

    [/autoit][autoit][/autoit][autoit][/autoit]


    gruß gmmg

  • Hallo gmmg,

    läuft die func bei dir mit den Beispieldaten (siehe Post #9) auch nicht, oder passiert dies nur mit deinen echten Daten?
    Mache einmal bitte direkt hinter deine Auswertung ein _ArrayDisplay($aObjects). Die Daten dieses Arrays kannst du dann ja indem du alle markierst und danach Copy Selected bestätigst kopieren und hier posten.
    Eventuell reicht auch schon ein

    [autoit]

    _ArrayDelete($aObjects,0)

    [/autoit]

    als 1. Zeile in die Func einzufügen, dann hätte dein auszuwertendes Array in Zeile 0 die Anzahl der Elemente,

    Edit: ich habe die func noch einmal umgebaut:

    [autoit]

    Func _GetUsers_Summary(ByRef $aObjects)
    if not IsArray($aObjects) Then SetError(1,0,0)
    Local $aCompanies = _ArrayUnique($aObjects, 3)
    ;_ArrayDisplay($aCompanies)
    _ArrayDelete($aCompanies,0)
    _ArraySort($aCompanies)
    ;_ArrayDisplay($aCompanies)
    Local $aResult[UBound($aCompanies)][2]
    For $i = 0 To UBound($aCompanies) -1
    $aResult[$i][0] = $aCompanies[$i]
    Next
    For $i = 0 To UBound($aResult) - 1
    $aTemp = _ArrayFindAll($aObjects, $aResult[$i][0], 0, 0, 0, 0, 2)
    $aResult[$i][1] = UBound($aTemp)
    Next
    Return $aResult
    EndFunc ;==>_GetAD_Summary

    [/autoit]

    teste doch bitte als 1. damit

    mfg autoBert

    Einmal editiert, zuletzt von autoBert (3. Februar 2011 um 11:58)

  • hallo autoBert,

    du bist ja fix mit antworten :)
    mit echtdaten läuft das nicht!
    hab die neue funktion eingebaut und es läuft ohne fehler durch!!! ich poste mal das komplette script!
    da sind aber noch jede menge excel ausgaben drin, mit formatierung :)

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <Excel.au3>
    #Include <File.au3>
    #include <AD.au3>
    #include <Array.au3>
    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;ldap attribute -> http://www.selfadsi.de/user-attributes-w2k3.htm

    [/autoit] [autoit][/autoit] [autoit]

    DIM $oMyRet, $oMyError, $oExcel, $saveas, $sOU
    Local $avArray[1] , $avArray_1[1], $aObjects
    _AD_Open()

    [/autoit] [autoit][/autoit] [autoit]

    ;auslesen der einzelnen OU's
    $aOUs = _AD_GetObjectsInOU($sOU, "(objectCategory=organizationalUnit)", 1, "name") ;"distinguishedName")
    If @error > 0 Then
    MsgBox(64, "Active Directory Functions - Example 2", "No OUs could be found")
    Else
    ;_ArrayDisplay($aOUs, "Active Directory Functions - Example 2 - All OUs starting with: '" & $sOU & "'")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;_ArrayDelete($aOUs, 0) ;löscht 1 eintrag aus dem array
    _ArraySort($aOUs)
    ;_ArrayDisplay($aOUs, "AD all Site OUs!")

    [/autoit] [autoit][/autoit] [autoit]

    ;erstelle excel dokument
    Local $oExcel = _ExcelBookNew() ;Create new book, make it visible
    _ExcelSheetDelete($oExcel, "Sheet1") ;Delete Sheet by string name of SheetName
    _ExcelSheetDelete($oExcel, "Sheet2") ;Delete Sheet by string name of SheetName
    _ExcelSheetDelete($oExcel, "Sheet3") ;Delete Sheet by string name of SheetName
    _ExcelSheetDelete($oExcel, "Tabelle1") ;Delete Sheet by string name of SheetName
    _ExcelSheetDelete($oExcel, "Tabelle2") ;Delete Sheet by string name of SheetName
    ;-----------------------

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(1000)

    [/autoit] [autoit][/autoit] [autoit]

    For $x = 1 to $aOUs[0]

    [/autoit] [autoit][/autoit] [autoit]

    $aObjects = _AD_GetObjectsInOU("OU=User,OU="&$aOUs[$x]&",DC=domäne,DC=int", "(&(objectcategory=person)(objectclass=user)(mail=*)(userAccountControl=512))", 2, "sAMAccountName,mail,company")
    ;_ArrayDisplay($aObjects)

    [/autoit] [autoit][/autoit] [autoit]

    If @error > 0 Then
    ;MsgBox(64, "", "Nichts gefunden Error: " & @error)
    Else

    [/autoit] [autoit][/autoit] [autoit]

    _GetUsers_Summary($aObjects);get company in site, zähle unser pro company

    [/autoit] [autoit][/autoit] [autoit]

    ;--------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    _ExcelSheetAddNew($oExcel, $aOUs[$x])
    _ExcelWriteCell($oExcel, "User", 1, 1) ;Write to the Cell
    _ExcelWriteCell($oExcel, "Email", 1, 2) ;Write to the Cell
    _ExcelWriteCell($oExcel, "Company", 1, 3) ;Write to the Cell
    With $oExcel.ActiveWorkbook.Sheets(1)
    .Columns("A:A").ColumnWidth = "30"
    .Columns("B:B").ColumnWidth = "50"
    .Columns("C:C").ColumnWidth = "50"
    .range("A1:C1") .Font.Bold = TRUE
    .range("A1:C1") .Font.Size = 14
    ;.range("A1:D1") .Font.Color = 0xffffff
    .range("A1:C1") .Interior.ColorIndex = 43
    ;.Name = $aOUs[$x]
    EndWith

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $aObjects[0][0]
    ;MsgBox(0,"", $aObjects[$i][0])
    $zeile = $i + 1
    IF $aObjects[0][0] <> "" Then
    _ExcelWriteCell($oExcel, $aObjects[$i][0], $zeile, 1)
    _ExcelWriteCell($oExcel, $aObjects[$i][1], $zeile, 2)
    _ExcelWriteCell($oExcel, $aObjects[$i][2], $zeile, 3)
    With $oExcel.ActiveWorkbook.Sheets(1)
    .Range("A"& $zeile &":C"& $zeile) .Interior.ColorIndex = 27
    .Range("A1:C"&$zeile).Borders.LineStyle = 1 ; setze einen Rahmen um die Zellen
    EndWith
    EndIf
    Next
    _ArrayAdd($avArray, $aOUs[$x] & ";" & $aObjects[0][0])
    _ExcelWriteCell($oExcel, $aObjects[0][0], $zeile + 2, 2)
    _ExcelWriteCell($oExcel, "All USER " & $aOUs[$x] & ":", $zeile + 2, 1)

    [/autoit] [autoit][/autoit] [autoit]

    With $oExcel.ActiveWorkbook.Sheets(1)
    .Range("A"& $zeile +2 &":B"& $zeile+2) .Interior.ColorIndex = 27
    .Range("A1:B"&$zeile +2).Borders.LineStyle = 1 ; setze einen Rahmen um die Zellen
    .Range("A"& $zeile +2 &":B"& $zeile+2) .Font.Bold = TRUE
    EndWith

    [/autoit] [autoit][/autoit] [autoit]

    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _AD_Close()
    _ExcelSheetDelete($oExcel, "Tabelle3") ;Delete Sheet by string name of SheetName
    _ExcelSheetAddNew($oExcel, "ZGesamt")
    _ExcelSheetOrderByName($oExcel, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;_ArrayDisplay($avArray)
    _ExcelWriteCell($oExcel, "Site", 1, 1) ;Write to the Cell
    _ExcelWriteCell($oExcel, "Anzahl User", 1, 2) ;Write to the Cell
    With $oExcel.ActiveWorkbook.Sheets("ZGesamt")
    .Columns("A:A").ColumnWidth = "30"
    .Columns("B:B").ColumnWidth = "50"
    .range("A1:B1") .Font.Bold = TRUE
    .range("A1:B1") .Font.Size = 14
    ;.range("A1:D1") .Font.Color = 0xffffff
    .range("A1:B1") .Interior.ColorIndex = 43
    ;.Name = $aOUs[$x]
    EndWith

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To _ArrayMaxIndex($avArray, 0, 1)
    ;MsgBox(0,"", $avArray[$i])
    $zeile_1 = $i + 1
    $eintrag = StringSplit($avArray[$i], ";")
    _ExcelWriteCell($oExcel, $eintrag[1], $zeile_1, 1)
    _ExcelWriteCell($oExcel, $eintrag[2], $zeile_1, 2)
    With $oExcel.ActiveWorkbook.Sheets("ZGesamt")
    .Range("A"& $zeile_1 &":B"& $zeile_1) .Interior.ColorIndex = 27
    .Range("A1:B"&$zeile_1).Borders.LineStyle = 1 ; setze einen Rahmen um die Zellen
    EndWith
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _ExcelWriteCell($oExcel, "=Summe(B2:B"& $zeile_1 ,$zeile_1 + 1 , 2) ;Write formula another way Uses A1 referencing, not R1C1
    _ExcelWriteCell($oExcel, "All User",$zeile_1 + 1 , 1) ;Write formula another way Uses A1 referencing, not R1C1
    With $oExcel.ActiveWorkbook.Sheets("ZGesamt") ; formatiert letzte Zeile
    .Range("A"& $zeile_1 +1 &":B"& $zeile_1 + 1) .Interior.ColorIndex = 27
    .Range("A"& $zeile_1 +1 &":B"& $zeile_1 + 1).Borders.LineStyle = 1 ; setze einen Rahmen um die Zellen
    .Range("A"& $zeile_1 +1 &":B"& $zeile_1 + 1) .Font.Bold = TRUE
    EndWith

    [/autoit] [autoit][/autoit] [autoit]

    ;$saveas = "C:\User_in Sites"
    ;_ExcelBookSaveAs($oExcel, $saveas, "xls")
    ;_ExcelBookClose($oExcel, 1, 0)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _ExcelSheetOrderByName($oExcel, $iDesc=0)
    ; Description::Order ExcelBook-Sheets by name ascending (default) or descending
    ; Parameter(s):$oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $iDesc - order descending on=1/off=0 (default)
    ; Requirement(s): #Include <Array.au3>
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0 and sets @error=1 - Specified object does not exist
    ; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
    ;===============================================================================
    Func _ExcelSheetOrderByName($oExcel, $iDesc=0)
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $iDesc <> 1 Then $iDesc = 0
    Local $aList = _ExcelSheetList($oExcel)
    _ArraySort($aList, $iDesc)
    Local $pos = 1
    For $i = 0 To UBound($aList) -1
    If $i = 0 Then
    _ExcelSheetMove($oExcel, $aList[$i], $pos, True)
    Else
    _ExcelSheetMove($oExcel, $aList[$i], $pos, False)
    $pos += 1
    EndIf
    Next
    Return 1
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetUsers_Summary(ByRef $aObjects)
    if not IsArray($aObjects) Then SetError(1,0,0)
    Local $aCompanies = _ArrayUnique($aObjects, 3)
    ;_ArrayDisplay($aCompanies)
    _ArrayDelete($aCompanies,0)
    _ArraySort($aCompanies)
    _ArrayDisplay($aCompanies) ; hier werden jetzt schon richtig die einzelnen companies aufgelistet
    Local $aResult[UBound($aCompanies)][2]
    For $i = 0 To UBound($aCompanies) -1
    $aResult[$i][0] = $aCompanies[$i]
    Next
    For $i = 0 To UBound($aResult) - 1
    $aTemp = _ArrayFindAll($aObjects, $aResult[$i][0], 0, 0, 0, 0, 2)
    $aResult[$i][1] = UBound($aTemp)
    Next
    Return $aResult
    EndFunc ;==>_GetAD_Summary

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    _ArrayDisplay($aCompanies) ; hier werden jetzt schon richtig die einzelnen companies aufgelistet, es fehlt nur noch die anzahl der user, die in den entsprechenden companys sind!

    gruß gmmg

    Einmal editiert, zuletzt von gmmg (3. Februar 2011 um 12:30)

  • hab die neue funktion eingebaut und es läuft ohne fehler durch!!!


    Oh, dann scheinst du Einträge in deinem Array zu haben bei dem die Spalte 2 (Company) nicht definiert also leer ist.

    ich poste mal das komplette script!


    wäre eigentlich nicht nötig da ich keine AD-Funktion habe (Einelplatz Netbook Win XP) wenn wirklich noch Fehler vorkommen sollten ist es hilfreicher (verfälschte) Daten einzstellen.

    mfg autoBert

  • autoBert

    so, hab jetzt mal 100 testdaten aus dem array "$aObjects" erstellt!

    Spoiler anzeigen
    [autoit]


    [0]|99|3|
    [1]|ftina|[email='ftireditors2@test.com'][/email]|Accounting Service
    [2]|mlaaa|[email='big2.creditors@test.com'][/email]|Accounting Service
    [3]|mlaaag|[email='anlla.agius@test.com'][/email]|Accounting Service
    [4]|mlaaat|[email='ane.attard@test.com'][/email]|Accounting Service
    [5]|mlaab|mlat.FTi.Com|Accounting Service
    [6]|mlaaba|[email='alder.barbara@test.com'][/email]|Accounting Service
    [7]|mlaabo|[email='ane.borg@test.com'][/email]|Accounting Service
    [8]|mlaacl|[email='ansia.calleja@test.com'][/email]|Accounting Service
    [9]|mlaacu|[email='Au.Curmi@test.com'][/email]|Accounting Service
    [10]|mlaade|[email='anette.demanuele@test.com'][/email]|Accounting Service
    [11]|mlaadu|[email='aair.duncan@test.com'][/email]|Accounting Service
    [12]|mlaage|[email='aw.gerardi@test.com'][/email]|Accounting Service
    [13]|mlaagl|[email='an.galea@test.com'][/email]|Accounting Service
    [14]|mlaamg|[email='Ail.Magro@test.com'][/email]|Accounting Services
    [15]|mlaamr|[email='ail.mercieca@test.com'][/email]|Accounting Service
    [16]|mlaan|[email='al.scicluna@test.com'][/email]|Accounting Service
    [17]|mlaas|[email='al.savona@test.com'][/email]|Accounting Service
    [18]|mlaasc|[email='aise.scicluna@test.com'][/email]|Accounting Service
    [19]|mlaasp|[email='Ael.Spiteri@test.com'][/email]|Accounting Service
    [20]|mlaat|[email='keatkins@test.com'][/email]|Accounting Service
    [21]|mlaawa|[email='a.watanabe@test.com'][/email]|Accounting Service
    [22]|mlabc|[email='crors19@test.com'][/email]|Accounting Service
    [23]|mlabgr|[email='bce.grima@test.com'][/email]|Accounting Service
    [24]|mlabmi|[email='brdette.micallef@test.com'][/email]|Accounting Service
    [25]|mlaca|[email='che.psaila@test.com'][/email]|Accounting Service
    [26]|mlacao|[email='ctina.azzopardi@test.com'][/email]|Accounting Service
    [27]|mlacat|[email='ctian.attard@test.com'][/email]|Accounting Service
    [28]|mlacaz|[email='clina.azzopardi@test.com'][/email]|Accounting Service
    [29]|mlacbe|[email='Ctian.Bezzina@test.com'][/email]|Accounting Service
    [30]|mlacbr|[email='celle.borg@test.com'][/email]|Accounting Service
    [31]|mlacbu|[email='cc.buhagiar@test.com'][/email]|Accounting Service
    [32]|mlacc|[email='caciscaldi@test.com'][/email]|Accounting Service
    [33]|mlaccl|[email='C.Carabott@test.com'][/email]|Accounting Service
    [34]|mlaccm|[email='ctianne.camilleri@test.com'][/email]|Accounting Service
    [35]|mlaccs|[email='C.Cassar@test.com'][/email]|Accounting Service
    [36]|mlacdi|[email='con.dingli-bennetti@meetingpointint.com'][/email]|GD Life Limited
    [37]|mlacfe|[email='ctine.fenech@meetingpointmalta.com'][/email]|Services Malta Ltd.
    [38]|mlacga|[email='lhools1.accounts@test.com'][/email]|Accounting Service
    [39]|mlachi|[email='ctian.hili@test.com'][/email]|Accounting Service
    [40]|mlacma|[email='c.micallef@test.com'][/email]|Accounting Service
    [41]|mlacmz|[email='ctianne.mizzi@test.com'][/email]|Accounting Service
    [42]|mlacpo|[email='crine.portelli@test.com'][/email]|Accounting Service
    [43]|mlacq|[email='crors24@test.com'][/email]|Accounting Service
    [44]|mlacsa|[email='crine.saliba@test.com'][/email]|Accounting Service
    [45]|mlacsl|[email='csaliba@test.com'][/email]|Accounting Service
    [46]|mlacvl|[email='Cene.Vella@test.com'][/email]|Accounting Service
    [47]|mlacxe|[email='cene.xuereb@test.com'][/email]|Accounting Service
    [48]|mlacxu|[email='ctian.xuereb@test.com'][/email]|Accounting Service
    [49]|mlada|icest.com|Accounting Service
    [50]|mladb|[email='da.bugeja@test.com'][/email]|Accounting Service
    [51]|mladba|[email='dn.barbara@test.com'][/email]|Accounting Service
    [52]|mladc|[email='doy.camilleri@test.com'][/email]|Accounting Service
    [53]|mladca|[email='dra.catania@test.com'][/email]|Accounting Service
    [54]|mladd|[email='da.delia@test.com'][/email]|Accounting Service
    [55]|mlade|[email='bia3.creditors@test.com'][/email]|Accounting Service
    [56]|mladga|[email='de.galea@test.com'][/email]|Accounting Service
    [57]|mladgi|[email='dnne.grima@test.com'][/email]|Accounting Service
    [58]|mladmi|[email='de.mifsud@test.com'][/email]|Accounting Service
    [59]|mladmu|[email='D.Muscat@test.com'][/email]|Accounting Service
    [60]|mladp|[email='done.spiteri@test.com'][/email]|Accounting Service
    [61]|mlaea|[email='crors18@test.com'][/email]|Accounting Service
    [62]|mlaeca|[email='e.carabott@test.com'][/email]|Accounting Service
    [63]|mlaemi|[email='eora.micallef@test.com'][/email]|Accounting Service
    [64]|mlaena|[email='e.nappa@test.com'][/email]|Accounting Service
    [65]|mlaesp|[email='eel.spiteri@test.com'][/email]|Accounting Service
    [66]|mlaet|[email='trort@meetingpointmalta.com'][/email]|Services Malta Ltd.
    [67]|mlaev|[email='el.vella@test.com'][/email]|Accounting Service
    [68]|mlafbu|[email='Fzia.Buhagiar@test.com'][/email]|Accounting Service
    [69]|mlafm|[email='maka.frantz@test.com'][/email]|Accounting Service
    [70]|mlagcr|[email='Gelle.Curmi@test.com'][/email]|Accounting Service
    [71]|mlagg|[email='gleorge.grima@test.com'][/email]|Accounting Service
    [72]|mlaggo|[email='ga.gouder@test.com'][/email]|Accounting Service
    [73]|mlagm|[email='ftcreditors@test.com'][/email]|Accounting Service
    [74]|mlagve|[email='getta.vella@test.com'][/email]|Accounting Service
    [75]|mlagvl|[email='Gella.Vella@test.com'][/email]|Accounting Service
    [76]|mlagza|[email='gio.zammit@test.com'][/email]|Accounting Service
    [77]|mlahfa|[email='hh.farrugia@test.com'][/email]|Accounting Service
    [78]|mlaig|mlMt.FTi.Com|Accounting Service
    [79]|mlaim|[email='chr4.creditors@test.com'][/email]|Accounting Service
    [80]|mlajaq|[email='jtte.aquilina@test.com'][/email]|Accounting Service
    [81]|mlajaz|[email='ctors22@test.com'][/email]|Accounting Service
    [82]|mlajba|[email='jca.bajada@test.com'][/email]|Accounting Service
    [83]|mlajbo|[email='j.bonnici@test.com'][/email]|Accounting Service
    [84]|mlajca|[email='jh.carabott@test.com'][/email]|Services Malta Ltd.
    [85]|mlajcc|[email='j.cauchi@test.com'][/email]|Accounting Service
    [86]|mlajco|[email='Jne.Cortis@test.com'][/email]|Accounting Service
    [87]|mlajcr|[email='jfer.caruana@test.com'][/email]|Accounting Service
    [88]|mlajd|[email='bia5.creditors@test.com'][/email]|Accounting Service
    [89]|mlajga|[email='j.gatt@test.com'][/email]|Accounting Service
    [90]|mlajl|[email='jete.galea@test.com'][/email]|Accounting Service
    [91]|mlajm|[email='jaline.thorpe@test.com'][/email]|Accounting Service
    [92]|mlajme|[email='jeline.mercieca@test.com'][/email]|Accounting Service
    [93]|mlajq|[email='jabriffa@test.com'][/email]|Accounting Service
    [94]|mlajs|mlMt.FTi.Com|Accounting Service
    [95]|mlajto|[email='j.torpiano@test.com'][/email]|Accounting Service
    [96]|mlajve|[email='jca.vella@test.com'][/email]|Accounting Services
    [97]|mlajza|[email='ctors14@test.com'][/email]|Accounting Service
    [98]|mlaka|yimeetingpointmalta.com|Meeting Point Malta Ltd.
    [99]|mlakaz|[email='kazzopardi@test.com'][/email]|Accounting Service

    [/autoit]

    in deiner Funktion listet er jetzt schon die einzelnen Companies Spalte 3 auf

    [autoit]


    Func _GetUsers_Summary(ByRef $aObjects)
    if not IsArray($aObjects) Then SetError(1,0,0)
    Local $aCompanies = _ArrayUnique($aObjects, 3)
    ;_ArrayDisplay($aCompanies)
    _ArrayDelete($aCompanies,0)
    _ArraySort($aCompanies)
    _ArrayDisplay($aCompanies) ; hier werden jetzt schon richtig die einzelnen companies aufgelistet
    Local $aResult[UBound($aCompanies)][2]
    For $i = 0 To UBound($aCompanies) -1
    $aResult[$i][0] = $aCompanies[$i]
    Next
    For $i = 0 To UBound($aResult) - 1
    $aTemp = _ArrayFindAll($aObjects, $aResult[$i][0], 0, 0, 0, 0, 2)
    $aResult[$i][1] = UBound($aTemp)
    Next
    Return $aResult
    EndFunc ;==>_GetAD_Summary

    [/autoit][autoit][/autoit][autoit][/autoit]

    wie aber bekomme ich jetzt die anzahl der user heraus, die in der jeweiligen company sind?

    gruß gmmg

  • Spoiler anzeigen
    [autoit]


    #include <Array.au3>
    #region Test Array
    Dim $aObjects[99][3] = [ _
    ["$ftina","ftireditors2@test.com","Accounting Service"], _
    ["$mlaaa","big2.creditors@test.com","Accounting Service"], _
    ["$mlaaag","anlla.agius@test.com","Accounting Service"], _
    ["$mlaaat","ane.attard@test.com","Accounting Service"], _
    ["$mlaab","mlat.FTi.Com","Accounting Service"], _
    ["$mlaaba","alder.barbara@test.com","Accounting Service"], _
    ["$mlaabo","ane.borg@test.com","Accounting Service"], _
    ["$mlaacl","ansia.calleja@test.com","Accounting Service"], _
    ["$mlaacu","Au.Curmi@test.com","Accounting Service"], _
    ["$mlaade","anette.demanuele@test.com","Accounting Service"], _
    ["$mlaadu","aair.duncan@test.com","Accounting Service"], _
    ["$mlaage","aw.gerardi@test.com","Accounting Service"], _
    ["$mlaagl","an.galea@test.com","Accounting Service"], _
    ["$mlaamg","Ail.Magro@test.com","Accounting Services"], _
    ["$mlaamr","ail.mercieca@test.com","Accounting Service"], _
    ["$mlaan","al.scicluna@test.com","Accounting Service"], _
    ["$mlaas","al.savona@test.com","Accounting Service"], _
    ["$mlaasc","aise.scicluna@test.com","Accounting Service"], _
    ["$mlaasp","Ael.Spiteri@test.com","Accounting Service"], _
    ["$mlaat","keatkins@test.com","Accounting Service"], _
    ["$mlaawa","a.watanabe@test.com","Accounting Service"], _
    ["$mlabc","crors19@test.com","Accounting Service"], _
    ["$mlabgr","bce.grima@test.com","Accounting Service"], _
    ["$mlabmi","brdette.micallef@test.com","Accounting Service"], _
    ["$mlaca","che.psaila@test.com","Accounting Service"], _
    ["$mlacao","ctina.azzopardi@test.com","Accounting Service"], _
    ["$mlacat","ctian.attard@test.com","Accounting Service"], _
    ["$mlacaz","clina.azzopardi@test.com","Accounting Service"], _
    ["$mlacbe","Ctian.Bezzina@test.com","Accounting Servicece"], _
    ["$mlacbr","celle.borg@test.com","Accounting Service"], _
    ["$mlacbu","cc.buhagiar@test.com","Accounting Service"], _
    ["$mlacc","caciscaldi@test.com","Accounting Service"], _
    ["$mlaccl","C.Carabott@test.com","Accounting Service"], _
    ["$mlaccm","ctianne.camilleri@test.com","Accounting Service"], _
    ["$mlaccs","C.Cassar@test.com","Accounting Service"], _
    ["$mlacdi","con.dingli-bennetti@meetingpointint.com","GD Life Limited"], _
    ["$mlacfe","ctine.fenech@meetingpointmalta.com","Services Malta Ltd."], _
    ["$mlacga","lhools1.accounts@test.com","Accounting Service"], _
    ["$mlachi","ctian.hili@test.com","Accounting Service"], _
    ["$mlacma","c.micallef@test.com","Accounting Service"], _
    ["$mlacmz","ctianne.mizzi@test.com","Accounting Service"], _
    ["$mlacpo","crine.portelli@test.com","Accounting Service"], _
    ["$mlacq","crors24@test.com","Accounting Service"], _
    ["$mlacsa","crine.saliba@test.com","Accounting Service"], _
    ["$mlacsl","csaliba@test.com","Accounting Service"], _
    ["$mlacvl","Cene.Vella@test.com","Accounting Service"], _
    ["$mlacxe","cene.xuereb@test.com","Accounting Service"], _
    ["$mlacxu","ctian.xuereb@test.com","Accounting Service"], _
    ["$mlada","icest.com","Accounting Service"], _
    ["$mladb","da.bugeja@test.com","Accounting Service"], _
    ["$mladba","dn.barbara@test.com","Accounting Service"], _
    ["$mladc","doy.camilleri@test.com","Accounting Service"], _
    ["$mladca","dra.catania@test.com","Accounting Service"], _
    ["$mladd","da.delia@test.com","Accounting Service"], _
    ["$mlade","bia3.creditors@test.com","Accounting Service"], _
    ["$mladga","de.galea@test.com","Accounting Service"], _
    ["$mladgi","dnne.grima@test.com","Accounting Service"], _
    ["$mladmi","de.mifsud@test.com","Accounting Service"], _
    ["$mladmu","D.Muscat@test.com","Accounting Service"], _
    ["$mladp","done.spiteri@test.com","Accounting Service"], _
    ["$mlaea","crors18@test.com","Accounting Service"], _
    ["$mlaeca","e.carabott@test.com","Accounting Service"], _
    ["$mlaemi","eora.micallef@test.com","Accounting Service"], _
    ["$mlaena","e.nappa@test.com","Accounting Service"], _
    ["$mlaesp","eel.spiteri@test.com","Accounting Service"], _
    ["$mlaet","trort@meetingpointmalta.com","Services Malta Ltd."], _
    ["$mlaev","el.vella@test.com","Accounting Service"], _
    ["$mlafbu","Fzia.Buhagiar@test.com","Accounting Service"], _
    ["$mlafm","maka.frantz@test.com","Accounting Service"], _
    ["$mlagcr","Gelle.Curmi@test.com","Accounting Service"], _
    ["$mlagg","gleorge.grima@test.com","Accounting Service"], _
    ["$mlaggo","ga.gouder@test.com","Accounting Service"], _
    ["$mlagm","ftcreditors@test.com","Accounting Service"], _
    ["$mlagve","getta.vella@test.com","Accounting Service"], _
    ["$mlagvl","Gella.Vella@test.com","Accounting Service"], _
    ["$mlagza","gio.zammit@test.com","Accounting Service"], _
    ["$mlahfa","hh.farrugia@test.com","Accounting Service"], _
    ["$mlaig","mlMt.FTi.Com","Accounting Service"], _
    ["$mlaim","chr4.creditors@test.com","Accounting Service"], _
    ["$mlajaq","jtte.aquilina@test.com","Accounting Service"], _
    ["$mlajaz","ctors22@test.com","Accounting Service"], _
    ["$mlajba","jca.bajada@test.com","Accounting Service"], _
    ["$mlajbo","j.bonnici@test.com","Accounting Service"], _
    ["$mlajca","jh.carabott@test.com","Services Malta Ltd."], _
    ["$mlajcc","j.cauchi@test.com","Accounting Service"], _
    ["$mlajco","Jne.Cortis@test.com","Accounting Service"], _
    ["$mlajcr","jfer.caruana@test.com","Accounting Service"], _
    ["$mlajd","bia5.creditors@test.com","Accounting Service"], _
    ["$mlajga","j.gatt@test.com","Accounting Service"], _
    ["$mlajl","jete.galea@test.com","Accounting Service"], _
    ["$mlajm","jaline.thorpe@test.com","Accounting Service"], _
    ["$mlajme","jeline.mercieca@test.com","Accounting Service"], _
    ["$mlajq","jabriffa@test.com","Accounting Service"], _
    ["$mlajs","mlMt.FTi.Com","Accounting Service"], _
    ["$mlajto","j.torpiano@test.com","Accounting Service"], _
    ["$mlajve","jca.vella@test.com","Accounting Services"], _
    ["$mlajza","ctors14@test.com","Accounting Service"], _
    ["$mlaka","yimeetingpointmalta.com","Meeting Point Malta Ltd."], _
    ["$mlakaz","kazzopardi@test.com","Accounting Service"]]
    #endregion

    [/autoit] [autoit][/autoit] [autoit]

    $bench = TimerInit()
    $aR = CountItems($aObjects)
    ConsoleWrite(Round(TimerDiff($bench) / 1000, 4) & " s" & @CRLF)
    _ArrayDisplay($aR)

    [/autoit] [autoit][/autoit] [autoit]

    Func CountItems($Array, $item = 2, $ignoreblank = False)
    If Not IsArray($Array) Then Return SetError(1, 0, 0)
    If $item > UBound($Array, 2) - 1 Then Return SetError(2, 0, 0)
    Local $aSource = $Array
    _ArraySort($aSource, 0, 0, 0, $item)
    Local $aResult[UBound($aSource)][2]
    Local $x = 1
    Local $i = 0
    Local $j = 1
    Local $z = 1
    While $j < UBound($aSource)
    If $aSource[$i][$item] <> $aSource[$j][$item] Then
    If $ignoreblank Then
    If $aSource[$i][$item] <> "" Then
    $aResult[$x][0] = $aSource[$i][$item]
    $aResult[$x][1] = $z
    $x += 1
    EndIf
    Else
    $aResult[$x][0] = $aSource[$i][$item]
    $aResult[$x][1] = $z
    $x += 1
    EndIf
    $i = $j
    $z = 0
    EndIf
    $z += 1
    $j += 1
    WEnd
    If $i = UBound($aSource) -1 Then
    $aResult[$x][0] = $aSource[UBound($aSource) - 1][$item]
    $aResult[$x][1] = 1
    EndIf
    If $i < UBound($aSource) -1 And $i > 1 Then
    $aResult[$x][0] = $aSource[$i][$item]
    $aResult[$x][1] = $z
    EndIf
    ReDim $aResult[$x + 1][2]
    $aResult[0][0] = $x
    _ArraySort($aResult, 0, 1, 0, 0)
    $aSource = ""
    Return SetError(0, 0, $aResult)
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    8 Mal editiert, zuletzt von UEZ (3. Februar 2011 um 14:06)

  • Hallo gmmg,

    hier die abgeänderte Func mit deinen Testdaten:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    #include <File.au3>
    Local $aTMP
    _FileReadToArray(@ScriptDir & "\AD.TXT", $aTMP)
    Local $aObjects[$aTMP[0]][3]
    For $i = 1 To $aTMP[0]
    $aSplit = StringSplit($aTMP[$i], "|")
    For $J = 2 To 4
    $aObjects[$i - 1][$J - 2] = $aSplit[$J]
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _ArrayDisplay($aObjects) ;dies ist das Ausgangsarray mit den Ergebnissen der AD-Funktion

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Array = _GetUsers_Summary($aObjects) ;dieses Array enthält die Ergebnisse
    If Not @error Then _ArrayDisplay($Array)

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetUsers_Summary(ByRef $aObjects)
    If Not IsArray($aObjects) Then SetError(1, 0, 0)
    _ArrayDelete($aObjects, 0)
    If Not IsArray($aObjects) Then SetError(2, 0, 0)
    Local $aCompanies = _ArrayUnique($aObjects, 3)
    _ArrayDelete($aCompanies, 0)
    _ArraySort($aCompanies)
    Local $aResult[UBound($aCompanies)][2]
    For $i = 0 To UBound($aCompanies) - 1
    $aResult[$i][0] = $aCompanies[$i]
    Next
    For $i = 0 To UBound($aResult) - 1
    $aTemp = _ArrayFindAll($aObjects, $aResult[$i][0], 0, 0, 0, 0, 2)
    $aResult[$i][1] = UBound($aTemp)
    Next
    Return $aResult
    EndFunc ;==>_GetUsers_Summary

    [/autoit]

    da das Array die Anzahl der Elemnte enthielt musste ich noch ein ArrayDelete einfügen. Das Ergebniss ist ein Array: autoit.de/wcf/attachment/12485/

    mfg autoBert

  • Ich habe meinen Code aktualisiert, so dass auch leere Felder dargestellt werden.

    Wie viele Einträge werden denn bearbeitet?

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • hallo UEZ,

    das sind ca 20 AD Sites mit ca 3000 usern!

    schau mir das mal an!!!

    funktioniert alles bisher bestens ;)
    danke nochmal ...

    gruß gmmg

    Einmal editiert, zuletzt von gmmg (3. Februar 2011 um 14:37)