在为所有文件生成哈希后,我正在尝试验证文件夹内的文件。
我可以成功获得 Hash 输出,但我在使其正常工作时遇到问题。
# Compare the files inside both folders togethor
$Results = @( Compare-Object -ReferenceObject $( Hash-Folder -Folder $FolderSource ) -DifferenceObject $( Hash-Folder -Folder $FolderDestination ) -Property Name, Hash -IncludeEqual:$False | Sort-Object -Unique | Format-Table -HideTableHeaders | Out-String -Stream -Width 125 )
#If there are no differences, all is ok
If ( $Results -eq $NULL ) {
Write-host "All files verified successfully"
{ Else {
# There must be some differences, which side?
ForEach ( $Result in $Results ) {
If ( $Result.SideIndicator -eq '<=' ) {
Write-Host "This file is different in the source " $Result.Trim()
}
If ( $Result.SideIndicator -eq '=>' ) {
Write-Host "This file is different in the destination " $Result.Trim()
}
}
}
}