-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCompare-FileHash.ps1
43 lines (36 loc) · 1.39 KB
/
Compare-FileHash.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function Compare-FileHash {
[CmdletBinding()]
param (
[ValidateScript({Test-Path $_ -PathType Container})]
$Source,
[ValidateScript({Test-Path $_ -PathType Container})]
$Destination
)
try {
$sourceFiles = Get-ChildItem -Path $Source -Recurse -File -ErrorAction Stop
$destinationFiles = Get-ChildItem -Path $Destination -Recurse -File -ErrorAction Stop
} catch {
Write-Warning "Could not get files: $_"
break
}
$outArr = @()
foreach($file in $sourceFiles) {
$h1 = Get-FileHash -Path $file.FullName
if ($destinationFiles.Where{$_.Name -eq $file.Name}) {
$h2 = Get-FileHash -Path $destinationFiles.Where{$_.Name -eq $file.Name}.FullName
if($h1.Hash -eq $h2.Hash) {
Write-Verbose "$($file.FullName) matches $($h2.path)"
} else {
$out = @{
SourceFile = $h1.Path;
SourceFileHash = $h1.Hash;
DestinationFile = $h2.Path;
DestinationFileHash = $h2.Hash;
}
Write-Output (New-Object -TypeName psobject -Property $out)
}
} else {
Write-Verbose "Could not fild file $($file.Name) in $Destination"
}
}
}