这是我写的脚本:
function Compare {
$file1 = Read-Host "Please enter the path of the first file you would like to compare"
$file2 = Read-Host "Please enter the path of the second file you would like to compare"
$outFile = Read-Host "Please enter the path to where you would like your output file."
Try{
$compareOne = Get-Content $file1
$comparetwo = Get-Content $file2
}
Catch{
Write-Host "The path you entered is either invalid or the file does not exist. "
}
Write-Host "Beginning comparison"
Compare-Object $compareOne $compareTwo | Out-File $outFile
Write-Host "Complete!"
}
Compare
这是我的输出:
InputObject | SideIndicator
------------|--------------
Value1 | <=
Value2 | <=
Value3 | =>
Value4 | =>
我是否可以以可以更改每列标题的方式格式化我的输出?
而不是=>
和<=
我可以给出差异实际上是在哪个文件中找到的?
这是我正在寻找的输出类型:
Value | File
------------|--------------
Value1 | $file1
Value2 | $file2
Value3 | $file2
Value4 | $file1
我对 PowerShell 还是很陌生,所以如果你能解释你的答案那就太好了,这样我就可以理解实际发生了什么。
我也在尝试制作这个“虚拟证明”,以便任何人都可以比较两个文本文件,而无需进一步输入。
任何帮助将不胜感激!