I have two directories. One is the Source one was a Copy of the source that could be changed. I need to compare the two directories to find if there are:
- New files in either directory
- Existing files that have changed in the Copy only.
I created the following and it shows me all that but it flags the changed files from both sides. Giving me two results for the same file. I want to filter already compared files so that only one instance shows.
Here is what I have
$VDrive = "C:\Temp"
$Set = "GroupA"
function check-hash{
$DefaultDir = "$VDrive\Default\Files"
$SetDir = "$VDrive\$Set\Files"
$SetArray = @()
$SetArray = @((Get-ChildItem -File -Path $SetDir -Recurse) | Where-Object { $_ -notmatch "Thumbs.db"}|
ForEach-Object {
[PSCustomObject]@{
h = (Get-FileHash $_.FullName -Algorithm SHA1).Hash
n = $_.Name
s = $_.Length
fn = $_.fullname
}})
$DefaultArray = @()
$DefaultArray = @((Get-ChildItem -File -Path $DefaultDir -Recurse) | Where-Object { $_-notmatch "Thumbs.db"}|
ForEach-Object {
[PSCustomObject]@{
h = (Get-FileHash $_.FullName -Algorithm SHA1).Hash
n = $_.Name
s = $_.Length
fn = $_.fullname
}})
Compare-Object -ReferenceObject $DefaultArray -DifferenceObject $SetArray -Property n,h,s -PassThru | ForEach-Object {
$Vfile = $($_.fn)
#if ($_.SideIndicator -eq "==" ) { "===$Vfile in passed Hash Check" }
if ($_.SideIndicator -eq "<=" ) { "Hash Update $Vfile - Default file Different" }
if ($_.SideIndicator -eq "=>" ) { "Hash Delete $Vfile - In Set not Default" }
}
}
check-hash
This returns <= and => for any file that is different. I just want one but I need to check both ways.