The most popular answer for this question involves the following Windows powershell code (edited to fix a bug):
$file1 = Get-Content C:\temp\file1.txt
$file2 = Get-Content C:\temp\file2.txt
$Diff = Compare-Object $File1 $File2
$LeftSide = ($Diff | Where-Object {$_.SideIndicator -eq '<='}).InputObject
$LeftSide | Set-Content C:\temp\file3.txt
I always get a zero byte file as the output, even if I remove the $Diff line.
Why is the output file always null, and how can it be fixed?
Perhaps instead of
PowerShell 2 might work better with: