Here, I'm trying to compare 2 folders and copy the difference in the third folder recursively.
Below is my code and I'm able to do most of the part, but unable to get the files copied in the exact folder structure as if in the Folder1. This script actually copy the files directly on the folder3 without any folders. This just copies the files alone from different folder and put them in the folder3. Any help is greatly appreciated.
$Folder1path = "M:\Technical\foldercompare\folder1"
$Folder2path = "M:\Technical\foldercompare\folder2"
$Folder3path = "M:\Technical\foldercompare\folder3"
$Folder1 = Get-childitem -path $Folder1path -Recurse
$Folder2 = Get-childitem -path $Folder2path -Recurse
Compare-Object -ReferenceObject $folder1 -DifferenceObject $Folder2
Compare-Object $Folder1 $Folder2 -Property Name, Length |
Where-Object {$_.SideIndicator -eq "<="} |
ForEach-Object {
Copy-Item "$Folder1path\$($_.name)" -Destination "$Folder3path" -Force -Recurse
}