Skip to content

Instantly share code, notes, and snippets.

@danieljurek
Created July 21, 2024 04:39
Show Gist options
  • Save danieljurek/b10cd2768b019f3de781cff3a212254d to your computer and use it in GitHub Desktop.
Save danieljurek/b10cd2768b019f3de781cff3a212254d to your computer and use it in GitHub Desktop.
function VerifyFile($original, $copy) {
Write-Host "." -NoNewline
# Fail if one or more file isn't present
if (!(Test-Path $original) -or !(Test-Path $copy)) {
Write-Host "File not found: $original, $copy"
return $false
}
# Get file size
$originalFileSize = (Get-Item $original).Length
$copyFileSize = (Get-Item $copy).Length
if ($originalFileSize -ne $copyFileSize) {
Write-Host "File sizes don't match: $original, $copy"
Write-Host "$original`: $originalFileSize"
Write-Host "$copy`: $copyFileSize"
return $false
}
# File hash
$originalHash = Get-FileHash $original
$copyHash = Get-FileHash $copy
if ($originalHash.Hash -ne $copyHash.Hash) {
Write-Host "File hashes don't match: $original, $copy"
Write-Host "$original`: $($originalHash.Hash)"
Write-Host "$copy`: $($copyHash.Hash)"
return $false
}
return $true
}
Get-ChildItem <<SOURCE_PATH>> -Recurse -File | Foreach-Object {
$original = $_.FullName
$relativePath = Resolve-Path -Path $_.FullName -Relative -RelativeBasePath i:\
$copy = Join-Path "\\<<DESTINATION__PATH>>" $relativePath
if (!(VerifyFile $original $copy)) {
Write-Host "!!!!!MISMATCH FOUND!!!!!!!"
}
}function VerifyFile($original, $copy) {
Write-Host "." -NoNewline
# Fail if one or more file isn't present
if (!(Test-Path $original) -or !(Test-Path $copy)) {
Write-Host "File not found: $original, $copy"
return $false
}
# Get file size
$originalFileSize = (Get-Item $original).Length
$copyFileSize = (Get-Item $copy).Length
if ($originalFileSize -ne $copyFileSize) {
Write-Host "File sizes don't match: $original, $copy"
Write-Host "$original`: $originalFileSize"
Write-Host "$copy`: $copyFileSize"
return $false
}
# File hash
$originalHash = Get-FileHash $original
$copyHash = Get-FileHash $copy
if ($originalHash.Hash -ne $copyHash.Hash) {
Write-Host "File hashes don't match: $original, $copy"
Write-Host "$original`: $($originalHash.Hash)"
Write-Host "$copy`: $($copyHash.Hash)"
return $false
}
return $true
}
Get-ChildItem <<SOURCE_PATH>> -Recurse -File | Foreach-Object {
$original = $_.FullName
$relativePath = Resolve-Path -Path $_.FullName -Relative -RelativeBasePath i:\
$copy = Join-Path "\\<<DESTINATION__PATH>>" $relativePath
if (!(VerifyFile $original $copy)) {
Write-Host "!!!!!MISMATCH FOUND!!!!!!!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment