I have a couple different powershell scripts that neither of which suits exactly what I need to know about two folders I am comparing. I want to compare the two in order to determine which one is the newer/changed of the two.
It is possible that the two folders can have exactly the same file names, but have different date timestamps on them. What is usually the best indicator is when a file size is different. A Changed file size and a new date time would tell me that it's the newer of the two.
I have used a couple different powershell scripts to try to make that determination. This script:
Compare-Object -ReferenceObject (dir $dir3 -Recurse | Where-Object {!$_.psiscontainer} | Get-Hash ) -DifferenceObject (dir $dir4 -Recurse |Where-Object {!$_.psiscontainer } | Get-Hash)
Tells me what is changed, but the information is too specific. I have to take the hash total & then find out what is changed. I then have to dig some more to see the differences between the files that are different.
This script:
# Create Hash Tables
$DriveX = @{}
$DriveY = @{}
# Fill Hash Tables
get-childitem $Source -rec | ?{!$_.PSisContainer} | %{$DriveX."$($_.FullName)" = $_.Length}
get-childitem $Dest -rec | ?{!$_.PSisContainer} | %{$DriveY."$($_.FullName)" = $_.Length}
# Check $DriveY with Elements from $DriveX
foreach($entry in $DriveX.Keys)
{
$name = $Entry -replace ($Source -replace "\\","\\"),$Dest
if($DriveX."$Entry" -eq $DriveY."$Name")
{
#Write-Host "[$Name] and [$Entry] Are the Same [$Entry]"
}
else
#{$Name}
{
$Name, $Length
#$DriveY."Length"
}
}
tells me what is different, but not enough information (about date time, file size, etc) to know what changed about the folder it says is different.
Ideally, I would like to know what is different, and how it is different. The file hash I believe will tell me that, but is there a way to take that output & get the info I need from it?
Thanks!