title: Sync Folders with Powershell - New and edited Files
body: <p>I am trying to Sync 2 Folders with Powershell.
  Comparing and copying any new Files works just fine. But I want to additionally copy all files that got modified in the reference Foler.</p>
  
  <p>The following Code works and copys all new Files which got created in the reference Folder.</p>
  
  <pre><code>$folderReference = 'C:\Users\Administrator\Desktop\TestA'
  $folderToSync = 'C:\Users\Administrator\Desktop\TestB'
  
  $referenceFiles = Get-ChildItem -Recurse -Path $folderReference 
  $FolderSyncFiles = Get-ChildItem -recurse -Path $folderToSync
  
  $fileDiffs = Compare-Object -ReferenceObject $referenceFiles -DifferenceObject $FolderSyncFiles 
  
  foreach ($File in $fileDiffs){
      try {
              if ($File.SideIndicator -eq "&lt;="){
  
                  $FullSourceObject = $File.InputObject.Fullname
                  $FullTargetObject = $File.InputObject.Fullname.Replace($folderreference, $folderToSync)
  
                  Write-Host "copy File: " $FullSourceObject
                  copy-Item -Path $FullSourceObject -Destination $FullTargetObject
              }
      }
      catch {
          Write-Error -Message "Something went wrong!" -ErrorAction Stop
      }
  }
  </code></pre>
  
  <p>Now I also want to copy the modified Files.
  I tried <code>-property LastWriteTime</code> after the <code>Compare-Object</code>but I get a WriteErrorException when running the code.</p>
  
  <p>Do you guys have some tips on how to get this Code to run properly?
  Thanks in advance</p>