Skip to content

Instantly share code, notes, and snippets.

@shawnwildermuth
Created June 8, 2018 22:56
Show Gist options
  • Save shawnwildermuth/bc795e6e54ce4703e4de45eceb138055 to your computer and use it in GitHub Desktop.
Save shawnwildermuth/bc795e6e54ce4703e4de45eceb138055 to your computer and use it in GitHub Desktop.
Verify Files with Checksums and Powershell
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