Summary: Easily add two Windows PowerShell arrays together.
If I have an array stored in one variable, and another array stored in another variable, how can I add them together?
Use the + operator to add to arrays together:
PS C:\> $a = 2,3,4
PS C:\> $b = 5,6,7
PS C:\> $c = $a + $b
PS C:\> $c
2
3
4
5
6
7
PS C:\>
you can use this
function Join-Arrays ($RightArray,$LeftArray,$RightJoinOn,$LeftJoinOn){$ResultsArray =@()foreach ($Right in $RightArray){$Left= $LeftArray |where {$_.$LeftJoinOn -eq $Right.$RightJoinOn}if ($Right.$RightJoinOn -eq $Left.$LeftJoinOn){$obj = New-Object psobject$Left.psobject.properties |% { $obj | Add-Member -MemberType NoteProperty -Name $_.Name -Value $_.Value }$Right.psobject.properties |% { $obj | Add-Member -MemberType NoteProperty -Name $_.Name -Value $_.Value -Force}$ResultsArray +=$obj}}