Visual Studio Code can be used to compare files.
"%LOCALAPPDATA%\Programs\Microsoft VS Code\code.exe" --diff file1.cs file2.cs
However, is it possible to use it to compare two texts stored in PowerShell variables?
$s1 = "abc
cde"
$s2 = "abc
xyz"
& "%LOCALAPPDATA%\Programs\Microsoft VS Code\code.exe" --diff ....?
The Compare-Object cmdlet just show two pieces of texts if they are different. It's really useless when the texts are big.
VSCode will only diff files, so save your buffers to files.
$s1 = "abc
cde"
$s2 = "abc
xyz"
$f1 = New-TemporaryFile
$f2 = New-TemporaryFile
$s1 | Out-File $f1.FullName
$s2 | Out-File $f2.FullName
& "C:\Program Files\Microsoft VS Code\Code.exe" --diff $f1.FullName $f2.FullName
Read-Host -Prompt "Hit ENTER after you have compared temp files, and they will be deleted"
Write-Host "Removing $($f1.FullName) and $($f2.FullName)"
Remove-Item $f1.FullName
Remove-Item $f2.FullName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With