creating an array with matching values form two other arrays

I’ve two arrays: $Networks and $DrNetworks. Each contains the Sql Server name and database name for each database that each server hosts. I want to create an array that hosts each source server & source database, ie Network, and it’s corresponding DR Server & Dr database, ie DrNetwork.

How can I do that?


$Networks contains

SqlServer1 Db1

SqlServer2 Db2

SqlServer3 Db3

$DrNetworks contains

DrSqlServer9 Db1

DrSqlServer8 Db2

DrSqlServer7 Db3

I want to create an array that has

SourceServer  SourceDb DrServer DrDb
SqlServer1  Db1  DrSqlServer9 Db1
SqlServer2  Db2 DrSqlServer8 Db2
SqlServer3  Db3 DrSqlServer7 Db3

A response to my previous post about the same issue answers my question.


This gave me what I was looking for…

foreach($obj in $Networks ) {
$Other = $DrNetworks | ?{$_.Database -eq $obj.Database}
foreach($subobj in $other){
$obj | Select SqlServer, Database, @{Name='DRSqlServer';Expression={$subObj.SqlServer}},