
# If the text matches the pattern, output a custom object # that displays text like this: # Line Operation Text # - # 59 added New text added # if( $_.InputObject -match $pattern)Įlseif( $_. if( $_.SideIndicator -eq "=" -or $_.SideIndicator -eq "=>") # Keep track of the current line number, using the line # numbers in the "after" file for reference. WinMerge is an open source project, which means that the program is maintained and developed by volunteers. If you need support, look at our support page for more information how you can get it. WinMerge 2.16.22 is the latest stable version, and is recommended for most users. $comparedLines = Compare-Object $content1 $content2 -IncludeEqual | WinMerge 2.16.22 - latest stable version. Get-Content annotates output objects with # a 'ReadCount' property that represents the line number in the file # that the text came from. # Get the content from each file $content1 = Get-Content $file1 $content2 = Get-Content $file2 # Compare the two files. # The pattern (if any) to use as a filter for file # differences $pattern = ".*" If you want to pretty up the output a bit and make the syntax cleaner, let me introduce Compare-File: That gives the nifty one-liner: PS C:\temp> Compare-Object (Get-Content files.txt) (Get-Content files2.txt) | The Compare-Object cmdlet lets you compare two sets of items, giving you a report on the differences between those two sets: PS G:\lee\tools> cd c:\tempĪ (Get-Content. If you’ve tried to diff files in PowerShell before, you might have seen the Compare-Object cmdlet.
