The following should clean up your array in PowerShell by leveraging Group-Object
Create an array called $exampleArray:
$exampleArray = @()
$names = @("Apple", "Banana", "Clark", "David", "Eddy")
$tOrB = @("True","")
#just for an example
1..20 | % {
$object = New-Object PSObject -Property @{
#Get random Name
d = $names[$(Get-Random -Maximum $names.Count)]
#do true / blank -- random
c = $tOrB[$(Get-Random -Maximum $tOrB.Count)]
b = $tOrB[$(Get-Random -Maximum $tOrB.Count)]
}
$exampleArray += $object
}
$exampleArray
We can then group by d:
#group "combine" by column d
$group = $exampleArray | Group-Object d
Once grouped we can iterate through the grouped names and build a new array called $combined:
$combined = @()
$group | %{
$object = New-Object PSObject -Property @{
d = $_.Name
}
if($_.Group.c -contains "True")
{
$object | Add-Member -MemberType NoteProperty -Name c -Value "True"
}
else
{
$object | Add-Member -MemberType NoteProperty -Name c -Value ""
}
if($_.Group.b -contains "True")
{
$object | Add-Member -MemberType NoteProperty -Name b -Value "True"
}
else
{
$object | Add-Member -MemberType NoteProperty -Name b -Value ""
}
$combined += $object
}
$combined
Note: If you already have the array loaded (in this case $exampleArray), you might be better off just doing a Where-Object off of that array... This is dependent on what exactly you are attempting to accomplish. The answer I provided is most likely over-kill