08 May,2012 by Jack Vamvas
Question: How can I compare two files and report on differences using Powershell ? I have two large T-SQL scripts , which both parse successfully on SSMS , but give me different results
Answer: Comparing two files is a common DBA task. Use a combination of Powershell Get-Content and Compare-Object.
Get-Content gets the content of the file at the specified location
Compare-Object compares the two items and reports on the differences
Create two variables and use Get-Content to assign the values. Compare the two variables using Compare-Object . Output the results to a file for analysis.
$strPrimary = Get-Content C:\primary.sql $strSecondary = Get-Content C:\secondary.sql Compare-Object $strPrimary $strSecondary >C:\compareResults.txt ##Results InputObject SideIndicator ----------- ------------- GROUP BY mem.[first] => => GROUP BY mem.[last] <=
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |