嗨,我正在尝试制作自己的插件来检查目录内的 md5 总和并将其与旧插件进行比较。
我在下面写了一个脚本
$Patch1= "C:\Users\User\Downloads\"
$Patch2= "D:\sqls\"
# Check both hashes are the same
Function Get-DirHash($Path1) {
gci -File -Recurse $Path1 | Get-FileHash -Algorithm MD5 | select -ExpandProperty Hash | Out-File "C:/Program Files/temp.txt" -NoNewline
$temp="C:/Program Files/temp.txt"
$hash=Get-FileHash -Algorithm MD5 $temp
$hash.Path=$Path1
return $hash
}
Function Get-DirHash2($Path2) {
gci -File -Recurse $Path2 | Get-FileHash -Algorithm MD5 | select -ExpandProperty Hash | Out-File "C:/Program Files/temp2.txt" -NoNewline
$temp2="C:/Program Files/temp2.txt"
$hash2=Get-FileHash -Algorithm MD5 $temp2
$hash2.Path=$Path2
return $hash2
}
Get-DirHash($Patch1).Hash
Get-DirHash2($Patch2).Hash
if (Get-DirHash($Patch1) -eq Get-DirHash2($Patch2)) {
Write-Host 'Get-FileHash results are consistent' -ForegroundColor Green
} else {
Write-Host 'Get-FileHash results are inconsistent!!' -ForegroundColor Red
}
但是输出表明哈希值总是相等的
Algorithm Hash Path
--------- ---- ----
MD5 1BF506BB988C14CD8D1F04F239AE401C
MD5 1BF506BB988C14CD8D1F04F239AE401C
Get-FileHash results are consistent
你们知道如何制作这个吗?