我們有一個~4gb的有效負載,我們需要將它們複製到多個地理位置,並且某些時候程序集(dll文件)會被損壞。我使用獲得哈希函數在PowerShell和我的示例代碼片段看起來是這樣的如何在複製後對源和目標執行MD5驗證
# PowerShell Invoke-Command source Machine has check
Clear-Host
Invoke-Command -ScriptBlock {dir C:\swtools\7-Zip -Recurse | Where-Object {!$_.psiscontainer } | get-hash | Out-File c:\temp\source.md5.txt}
# PowerShell Invoke-Command on Remote Computer to check filehash at Dest
Clear-Host
Invoke-Command -Computer Remote_Host -ScriptBlock {dir e:\downloads\7-zip -Recurse | Where-Object {!$_.psiscontainer } | get-hash } | Out-File c:\temp\dest.md5.txt
# PowerShell compare to check if the md5 hashes are equal at source and dest
Compare-Object $(Get-Content c:\temp\source.md5.txt) $(Get-Content c:\temp\dest.md5.txt) -includeequal
這並不因爲Get-哈希的輸出包含文件路徑添加到文件名上解決問題,所以我真的不能與文件名和哈希值進行1:1比較,源文件名和散列值來自目的地,因爲輸出包含完整文件路徑,因此輸出文件路徑不同
那麼,確保從源複製到所有程序集的md5校驗和的最佳方法是什麼?目的地是否匹配?
注:我沒有看創建額外的文件,我只推動文件名和散列通過正則表達式等,時間和內存將是一個問題。
爲什麼不能通過文件先運行腳本並修改文件名?當然,你有一個算法將源代碼轉換爲目標路徑? –