What is the most performant way of evaluating two separate powershell objects populated with data from Invoke-SqlCmd to see if the result sets are the same and to highlight any differences assuming the result sets are not ordered?
Would it be best to take my $Query1 and convert each system.data.datarow into a concatenated string and then do a Contains against every system.data.datarow of $Query2? I am not so much concerned about what in each data row is different, but just the fact that a data row in $result1 does not match up with a data row in $result2. Would it be better to use a hashtable to accomplish this?
$result1 = Invoke-DbaQuery -SqlInstance mySqlInstance -database TESTDB -Query "SELECT TOP 2 * from myTable ORDER BY EmployeeID DESC"
$result2 = Invoke-DbaQuery -SqlInstance mySqlInstance -database TESTDB -Query "SELECT TOP 2 * from myTable ORDER BY EmployeeID ASC"
foreach($row in $result1) {
$rowString1 = Out-String -InputObject $row #| out-gridview
foreach($row2 in $result2) {
$rowString2 = Out-String -InputObject $row2 #| out-gridview
if($rowString1.String -eq $rowString2.String)
{
write-host 'there is a match!'
break;
}
else
{
write-host 'there is not a match. Keep Searching'
}
}
}
Edit: string search is too slow