kor Posted February 6, 2015 Posted February 6, 2015 I'm drawing a blank here as I don't recall that I've ever had to do this exact thing. Basically I'm doing an AD query where I get a 1 dimensional array of values that contains only 1 column. I then need to do an additional query to lookup each user from the first array to get additional data about each user. That part I already have figured out. Where I'm stuck is trying to figure out how to take the result of each line from the first array and populate all the results into a single new array? Does that make sense? What I have so far. But it's not what I want because I get an array for EACH user, rather than 1 array containing the results of all users from the For Loop. #include <AD.au3> #include <Array.au3> _AD_Open() Global $sGroup = "IS Department" ; group name $aResult = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) _ArrayDisplay($aResult) For $i = 1 To UBound($aResult) - 1 $aResult1 = _AD_GetObjectProperties($aResult[$i], "displayname,description,physicalDeliveryOfficeName") _ArrayDisplay($aResult1) Next _AD_Close()
water Posted February 6, 2015 Posted February 6, 2015 Something like this - I know it is far from being beautiful, but it works: #include <AD.au3> #include <Array.au3> _AD_Open() Global $sGroup = "IS Department" ; group name $aResult = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) _ArrayDisplay($aResult) For $i = 1 To UBound($aResult) - 1 $aResult1 = _AD_GetObjectProperties($aResult[$i], "displayname,description,physicalDeliveryOfficeName") $sDN = "" $sDesc = "" $sDO = "" For $j = 1 To $aResult1[0][0] If $aResult1[$j][0] = "displayname" Then $sDN = $aResult1[$j][1] ElseIf $aResult1[$j][0] = "description" Then $sDesc = $aResult1[$j][1] ElseIf $aResult1[$j][0] = "physicalDeliveryOfficeName" Then $sDO = $aResult1[$j][1] EndIf Next $aResult[$i] = $aResult[$i] & "," & $sDN & "," & $sDesc & "," & $sDO _ArrayDisplay($aResult1) Next _ArrayDisplay($aResult) _AD_Close() 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
kor Posted February 6, 2015 Author Posted February 6, 2015 Something like this - I know it is far from being beautiful, but it works: #include <AD.au3> #include <Array.au3> _AD_Open() Global $sGroup = "IS Department" ; group name $aResult = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) _ArrayDisplay($aResult) For $i = 1 To UBound($aResult) - 1 $aResult1 = _AD_GetObjectProperties($aResult[$i], "displayname,description,physicalDeliveryOfficeName") $sDN = "" $sDesc = "" $sDO = "" For $j = 1 To $aResult1[0][0] If $aResult1[$j][0] = "displayname" Then $sDN = $aResult1[$j][1] ElseIf $aResult1[$j][0] = "description" Then $sDesc = $aResult1[$j][1] ElseIf $aResult1[$j][0] = "physicalDeliveryOfficeName" Then $sDO = $aResult1[$j][1] EndIf Next $aResult[$i] = $aResult[$i] & "," & $sDN & "," & $sDesc & "," & $sDO _ArrayDisplay($aResult1) Next _ArrayDisplay($aResult) _AD_Close() What would you recommend to get each value to be its own column? Stringsplit or other?
water Posted February 6, 2015 Posted February 6, 2015 The function above should return a 1D array and later you want to split each element? 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
kor Posted February 6, 2015 Author Posted February 6, 2015 The function above should return a 1D array and later you want to split each element? Correct. Each element in its own cell.
water Posted February 6, 2015 Posted February 6, 2015 Then StringSplit is the way to go. 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
kor Posted February 6, 2015 Author Posted February 6, 2015 Then StringSplit is the way to go. I run into the same problem as the original question. How would I use stringsplit to take an array of elements and populate a new array!
water Posted February 6, 2015 Posted February 6, 2015 Looping through the source array, Stringsplit an element and then use the resulting array to populate the target array. If you can post an example of the source and the desired target I can provide the needed code. 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
kor Posted February 6, 2015 Author Posted February 6, 2015 Looping through the source array, Stringsplit an element and then use the resulting array to populate the target array. If you can post an example of the source and the desired target I can provide the needed code. #include <Array.au3> Local $aArray[2][1] = [["mjones,job1,department1,office1"], ["jsmith,job2,department2,office2"]] Local $aArray1[2][4] = [["mjones" ,"job1","department1","office1"], ["jsmith","job2","department2","office2"]] _ArrayDisplay($aArray) _ArrayDisplay($aArray1)
Solution water Posted February 6, 2015 Solution Posted February 6, 2015 (edited) #include <Array.au3> #include <StringConstants.au3> Local $aSource[2][1] = [["mjones,job1,department1,office1"], ["jsmith,job2,department2,office2"]] Local $aTarget[2][4] For $i = 0 To UBound($aSource, 1) - 1 $aSplit = StringSplit($aSource[$i][0], ",", $STR_NOCOUNT) For $j = 0 To UBound($aSplit, 1) - 1 $aTarget[$i][$j] = $aSplit[$j] Next Next _ArrayDisplay($aSource) _ArrayDisplay($aTarget) Edited February 6, 2015 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
water Posted February 6, 2015 Posted February 6, 2015 This version works for a 2D source array with only one column AND for a 1D array. #include <Array.au3> #include <StringConstants.au3> ; Local $aSource[2][1] = [["mjones,job1,department1,office1"], ["jsmith,job2,department2,office2"]] Local $aSource[2] = ["mjones,job1,department1,office1", "jsmith,job2,department2,office2"] Local $aTarget[2][4] Local $iSourceDim = UBound($aSource, 0) For $i = 0 To UBound($aSource, 1) - 1 If $iSourceDim = 1 Then $aSplit = StringSplit($aSource[$i], ",", $STR_NOCOUNT) Else $aSplit = StringSplit($aSource[$i][0], ",", $STR_NOCOUNT) EndIf For $j = 0 To UBound($aSplit, 1) - 1 $aTarget[$i][$j] = $aSplit[$j] Next Next _ArrayDisplay($aSource) _ArrayDisplay($aTarget) 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
kor Posted February 9, 2015 Author Posted February 9, 2015 (edited) expandcollapse popup#include <AD.au3> #include <Array.au3> _AD_Open() Global $sGroup = "ACC_TRAVEL" ; group name Global $aMembers, $aUserProperties, $aSplit, $aFinal $aMembers = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) _ArrayDisplay($aMembers) For $i = 1 To UBound($aMembers) - 1 $aUserProperties = _AD_GetObjectProperties($aMembers[$i], "displayname,description,physicalDeliveryOfficeName") ;_ArrayDisplay($aUserProperties) Local $sDN = "", $sDesc = "", $sDO = "" For $n = 1 To $aUserProperties[0][0] If $aUserProperties[$n][0] = "displayname" Then $sDN = $aUserProperties[$n][1] ElseIf $aUserProperties[$n][0] = "description" Then $sDesc = $aUserProperties[$n][1] ElseIf $aUserProperties[$n][0] = "physicalDeliveryOfficeName" Then $sDO = $aUserProperties[$n][1] EndIf Next $aMembers[$i] = $aMembers[$i] & "," & $sDN & "," & $sDesc & "," & $sDO Next _ArrayDisplay($aMembers) For $i = 1 To UBound($aMembers) - 1 $aSplit = StringSplit($aMembers[$i], ",", 2) _ArrayDisplay($aSplit) For $n = 1 To UBound($aSplit, 1) - 1 $aFinal[$i][$n] = $aSplit[$n] Next Next _ArrayDisplay($aFinal) _AD_Close() I get the following error: (46) : ==> Subscript used on non-accessible variable.: $aFinal[$i][$n] = $aSplit[$n] $aFinal^ ERROR EDIT: I can get this to work IF I define $aFinal as $aFinal[12][4] However I can't always know how big or small the array is going to be. The output is dynamic and changes the number of columns depending on which group I point it at. Edited February 9, 2015 by kor
water Posted February 9, 2015 Posted February 9, 2015 Where do you define $aFinal as an array? 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
kor Posted February 9, 2015 Author Posted February 9, 2015 Where do you define $aFinal as an array? Up at the top in my Global
water Posted February 9, 2015 Posted February 9, 2015 The error simply means that $aFinal isn't an array when you try to access it. Global $aTest $atest[1] = "x" Returns the same error messge. Where do you use $aFinal in your script? Do you use it as a plain variable? Maybe a typo? 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
kor Posted February 9, 2015 Author Posted February 9, 2015 (edited) The error simply means that $aFinal isn't an array when you try to access it. Global $aTest $atest[1] = "x" Returns the same error messge. Where do you use $aFinal in your script? Do you use it as a plain variable? Maybe a typo? My entire script is posted. I define $aFinal as a variable at the top, and the first time I try and populate it is in the stringsplit loop. If the $afinal array is declared at the top as $aFinal[12][4] then the entire script works fine. But what happens when I query a new group that has 50 members. or 4 members? I'm not sure what I'm doing wrong. $aFinal is only there as a way for me to logical see the progression of the arrays in the code... so that I know that $aFinal is the final result of all the data and that is the one that I want to display. Your original code got confusing when you have just generic 'source' and 'target', but there are multiple 'sources' since the data is moving between 3 different arrays. EDIT: Entire code posted again. expandcollapse popup#include <AD.au3> #include <Array.au3> _AD_Open() Global $sGroup = "ACC_TRAVEL" ; group name Global $aMembers, $aUserProperties, $aSplit, $aFinal[12][4] $aMembers = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) _ArrayDisplay($aMembers) For $i = 1 To UBound($aMembers) - 1 $aUserProperties = _AD_GetObjectProperties($aMembers[$i], "displayname,description,physicalDeliveryOfficeName") ;_ArrayDisplay($aUserProperties) Local $sDN = "", $sDesc = "", $sDO = "" For $n = 1 To $aUserProperties[0][0] If $aUserProperties[$n][0] = "displayname" Then $sDN = $aUserProperties[$n][1] ElseIf $aUserProperties[$n][0] = "description" Then $sDesc = $aUserProperties[$n][1] ElseIf $aUserProperties[$n][0] = "physicalDeliveryOfficeName" Then $sDO = $aUserProperties[$n][1] EndIf Next $aMembers[$i] = $aMembers[$i] & "," & $sDN & "," & $sDesc & "," & $sDO Next ;_ArrayDisplay($aMembers) For $i = 1 To UBound($aMembers) - 1 $aSplit = StringSplit($aMembers[$i], ",", 2) ;_ArrayDisplay($aSplit) For $n = 0 To UBound($aSplit) - 1 ;ConsoleWrite($i & " .. " & $aSplit[$n] & @CR) $aFinal[$i][$n] = $aSplit[$n] Next Next _ArrayDisplay($aFinal) _AD_Close() Edited February 9, 2015 by kor
water Posted February 9, 2015 Posted February 9, 2015 You defined $aFinal as a simple variable. That's why you get the error message. To define the dimensions of an array you have to set them when defining the array (implicitly or explicitly). Later you can use ReDim to modify the dimensions (within limits). The problem with your approach is that you do not know how many columns (= members of a group) you will get. Let's say you have a group with 5 members so $aFinal will have 5 columns. The next group has 8 members. So you need to ReDim the array to hold 8 columns. I have no time to post a solution right now. Maybe tomorrow? 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
kor Posted February 9, 2015 Author Posted February 9, 2015 (edited) SUCCESS! Thank you water. The redim command after seeing the example in the help file really made it click that I could use UBound within the subscript value. Working code below. #include <AD.au3> #include <Array.au3> _AD_Open() Global $sGroup = "ACC_TRAVEL" ; group name Global $aMembers, $aUserProperties, $aSplit, $aFinal $aMembers = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) ; get group membership recursivly For $i = 1 To UBound($aMembers) - 1 $aUserProperties = _AD_GetObjectProperties($aMembers[$i], "displayname,description,physicalDeliveryOfficeName") ; get AD properties for each group member Local $sDN = "", $sDesc = "", $sDO = "" ; convert 2 dimensional array into a 1 dimensional array and repopulate For $n = 1 To $aUserProperties[0][0] If $aUserProperties[$n][0] = "displayname" Then $sDN = $aUserProperties[$n][1] ElseIf $aUserProperties[$n][0] = "description" Then $sDesc = $aUserProperties[$n][1] ElseIf $aUserProperties[$n][0] = "physicalDeliveryOfficeName" Then $sDO = $aUserProperties[$n][1] EndIf Next $aMembers[$i] = $aMembers[$i] & "," & $sDN & "," & $sDesc & "," & $sDO Next Local $aFinal[UBound($aMembers)][4] ; resize final array based on dimensions from source array For $i = 1 To UBound($aMembers) - 1 $aSplit = StringSplit($aMembers[$i], ",", 2) ; split values from CSV into each cell For $n = 0 To UBound($aSplit) - 1 $aFinal[$i][$n] = $aSplit[$n] ; populate final array Next Next _ArrayDisplay($aFinal) ; display final array _AD_Close() Edited February 9, 2015 by kor
water Posted February 9, 2015 Posted February 9, 2015 BTW: You should change line $aMembers = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False) to $aMembers = _AD_RecursiveGetGroupMembers($sGroup, 10, False, False) because _AD_GetObjectProperties will not return a valid result if you pass the groupname plus the parent group name (like: groupname|name of parent group) 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
water Posted February 9, 2015 Posted February 9, 2015 Another BTW: You won't get valid properties "displayname,description,physicalDeliveryOfficeName" for groups contained in the group you run _AD_RecursiveGetGroupMembers for. So you would need to check the objectclass and only run _AD_GetObjectProperties on users. 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now