Powershell输出哈希比较结果

时间:2018-03-12 16:56:05

标签: powershell hash output comparison

我正在开发一个Powershell脚本,该脚本比较两个不同文件路径的哈希值,并返回结果是否匹配。到目前为止,这是脚本:

$Source = Get-ChildItem –Path \\Server1\D$\path | foreach  {Get-FileHash –Path $_.FullName}
$Target = Get-ChildItem –Path \\Server2\C$\path | foreach  {Get-FileHash –Path $_.FullName}


$HashResult = (Compare-Object -ReferenceObject $Source -DifferenceObject $Target -Property hash -PassThru).Path



if ($Source.Hash -eq $Target.Hash) {
Write-Host 'The source and destination match.' -ForegroundColor Green
} else {
Write-Host 'The following files have differences between the source and destination: ' -ForegroundColor Red
$HashResult
}

到目前为止它的工作情况如下,以下是运行时得到的结果:

The following files have differences between the source and destination:
\\Server2\C$\path\AnotherTestFile.rtf
\\Server2\C$\path\Pizzaisnumberone.txt
\\Server2\C$\path\MoreTestingFiles.bmp
\\Server2\C$\path\RandomFile.txt
\\Server2\C$\path\PSTESTFILE.txt
\\Server2\C$\path\TESTDIFF.txt
\\Server1\D$\path\RandomFile.txt
\\Server1\D$\path\TESTDIFF.txt
但是,这就是问题所在。我想让输出更容易阅读,因为这将最终生成电子邮件警报。有没有办法划分哈希比较结果,以便您只能在变量中存储它的某些部分?我已经尝试将输出作为一个整体添加到一个变量中并且它有效,但这只会让我回到我开始的地方。

以下是输出的示例:

The following files appear in the destination folder but not in the source:
\\Server2\C$\path\AnotherTestFile.rtf
\\Server2\C$\path\Pizzaisnumberone.txt
\\Server2\C$\path\MoreTestingFiles.bmp

The following files have differences between the two paths:

\\Server2\C$\path\PSTESTFILE.txt
\\Server2\C$\path\TESTDIFF.txt
\\Server1\D$\path\RandomFile.txt
\\Server1\D$\path\TESTDIFF.txt

基本上,我只是希望能够将输出模型化为我想要的,而不是只是大量转储文件路径并强制阅读电子邮件的人必须解密它。这怎么可能?

0 个答案:

没有答案