title: Compare 2 Folders and copy the difference in another folder - my code missing something
body: <p>Here, I'm trying to compare 2 folders and copy the difference in the third folder recursively.</p>
  <p>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.</p>
  <pre><code>$Folder1path = &quot;M:\Technical\foldercompare\folder1&quot;
  $Folder2path = &quot;M:\Technical\foldercompare\folder2&quot;
  $Folder3path = &quot;M:\Technical\foldercompare\folder3&quot;
  $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 &quot;&lt;=&quot;} | 
  ForEach-Object {
              Copy-Item &quot;$Folder1path\$($_.name)&quot; -Destination &quot;$Folder3path&quot; -Force -Recurse
  }
  </code></pre>