<p>I have two arrays of <code>System.Data.DataRow</code> objects which I want to compare. </p>

<p>The rows have two columns A and B. Column A is a key and I want to find out which rows have had their B column changed and which rows have been added or deleted. </p>

<p><strong>How do I do this in PowerShell?</strong></p>

[{'answer_id': 22048, 'author': 'hollystyles', 'author_id': 2083160, 'author_profile': 'https://Stackoverflow.com/users/2083160', 'pm_score': 0, 'selected': False, 'text': '<p>Do you need two arrays of DataRows? the DataRow object has a RowState property which will give you what you require. See the MSDN Docs: <a href="http://msdn.microsoft.com/en-us/library/system.data.datarow.rowstate.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/</a></p>\n'}, {'answer_id': 22256, 'author': 'Steven Murawski', 'author_id': 1233, 'author_profile': 'https://Stackoverflow.com/users/1233', 'pm_score': 3, 'selected': True, 'text': '<p>I wrote a script to do this a little while back.  The script (Compare-QueryResults.ps1) is available <a href="http://podcast.acoupleofadmins.com/media/Scripts/Compare-QueryResults.ps1" rel="nofollow noreferrer">here</a> and you will also need my Run-SQLQuery script (available <a href="http://podcast.acoupleofadmins.com/media/scripts/Run-SQLQuery.ps1" rel="nofollow noreferrer">here</a>) or you can replace that with a script or function of your own.</p>\n\n<p>Basically, what the script does is take the results of each of your queries and break the datarows apart so that each field is its own object.  It then uses Compare-Object to check for any differences between the data in those rows.  It returns a comparison object that shows you all the differences between the data returned.</p>\n\n<p>The results are an object, so you can save them to a variable and use Sort-Object or the Format-* cmdlets with them.</p>\n\n<p>Good luck.  If you have any problems with the scripts, let me know, I\'d be happy to walk you through them.  I\'ve been using them for application testing, seeing what rows are being modified by different actions in a program.</p>\n'}, {'answer_id': 48471891, 'author': 'Dongminator', 'author_id': 1178960, 'author_profile': 'https://Stackoverflow.com/users/1178960', 'pm_score': 1, 'selected': False, 'text': '<p>To simply compare two System.Data.DataRow, you can do something like this: </p>\n\n<pre><code>foreach ($property in ($row1 | Get-Member -MemberType Property)) {\n    $pName = $property.Name\n\n    if ($row1.$pName -ne $row2.$pName) {\n        Write-Host "== $pName =="\n        $row1.$pName\n        $row2.$pName\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/21956', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/966/']