Created
June 8, 2018 22:56
-
-
Save shawnwildermuth/bc795e6e54ce4703e4de45eceb138055 to your computer and use it in GitHub Desktop.
Verify Files with Checksums and Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$source = "d:\videoprojects\hwfilm\", | |
[string]$dest = "g:\hwfilm\", | |
[switch]$debug | |
) | |
$sourceFileList = Get-ChildItem -Path $source -Recurse | Sort-Object -Property FullName | |
write-host "Files = $($sourceFileList.Length)" | |
foreach ($file in $sourceFileList) { | |
$fullPath = $file.fullName.Substring($source.Length) | |
$destFilePath = Join-Path -Path $dest -ChildPath $fullPath | |
$exist = Test-Path $destFilePath | |
if ($exist) { | |
$sourceHash = Get-FileHash -Path $file.FullName -Algorithm MD5 | |
$destHash = Get-FileHash -Path $destFilePath -Algorithm MD5 | |
if ($sourceHash.Hash -eq $destHash.Hash) { | |
if ($debug -eq $true) { | |
write-host $file.fullName | |
} | |
else { | |
write-host -NoNewline "." | |
} | |
} | |
else { | |
if ($debug -eq $true) { write-host "" } | |
write-host "Failed $($file.name)" -ForegroundColor Red | |
Add-Content '.\badFiles.txt' $destFilePath | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment