Hello all,
I do not know enough to ask the right questions to do what I need to do. So if this is answered already … apologies.
I have 2 array objects that need to be joined and have the results of 2nd object but with 1st count joined by same value
For example:
# Active Directory computer export > grouped by organization and count per organization
$group_01 = $computers | ForEach-Object {
[PSCustomObject]@{
'Organization' = $_.Organization
'Computer' = $_.Name
}
} | Group-Object -Property Organization | Sort-Object -Property Count -Descending | Select @{N='Organization'; E={$_.Name}}, Count
<# result
Organization Count
------------ -----
Org_01 3
Org_02 3
Org_03 2
Org_04 2
Org_05 2
Org_06 1
Org_07 1
Org_08 1
Org_09 1
Org_10 1
Org_11 1
Org_12 1
Org_13 1
Org_14 1
Org_15 1
Org_16 1
Org_17 1
Org_18 1
#>
# 10 percent random subset of $computers > grouped by organization and count per organization
$group_02 = $computers_filter | ForEach-Object {
[PSCustomObject]@{
'Organization' = $_.Organization
'Computer' = $_.Name
}
} | Group-Object -Property Organization | Sort-Object -Property Count -Descending | Select @{N='Organization'; E={$_.Name}}, Count
<# result
Organization Count
------------ -----
Org_01 1
Org_02 1
#>
What is needed is similar to SQL statement result below:
SELECT tbl_Group_02.Organization, tbl_Group_02.Count AS Group_02_Count, tbl_Group_01.Count AS Group_01_Count
FROM tbl_Group_02 INNER JOIN tbl_Group_01 ON tbl_Group_02.Organization = tbl_Group_01.Organization;
<# result
Organization Group_02_Count Group_01_Count
Org_01 1 3
Org_02 1 3
#>