title: How I can compare and move data from A to B in Powershell older than x Days?
body: <p>I have a Problem with my Powershell Script. ;( 
  I want to <strong>delete/ move/ compare</strong> with Powershell. </p>
  
  <p><strong>Here my Idea:</strong> </p>
  
  <p>If I start the Script I remove all empty folder from A. After that I want Move all Data from A to B that x Days older. (Here is my first problem) </p>
  
  <p>If I make copy it works fine. </p>
  
  <p>A other Idea is to compare A and B and only the diffrend to copy or move. (But I don't know how I can do this)</p>
  
  <p><strong>Here is my Code:</strong> </p>
  
  <pre><code>function removeFiles($source,$destination){
      $elements = Get-ChildItem $source -Recurse
      foreach($element in $elements){
          if(($element.PSIsContainer) -and (!(Get-ChildItem -Recurse -Path $element.FullName))){
              Write-Host "DELETE: " $element.FullName
              Remove-Item $element.FullName -Confirm:$false
          }
      }
  }
  
  function copyFiles($source,$destination,$days){
      $elements = Get-ChildItem $source -Recurse
      $lastwrite = (Get-Date).AddDays(-$days)
      foreach($element in $elements){
          if($element.creationTime -le $lastwrite){
              $targetFile = $destination + $element.FullName.SubString($source.Length)
              if($element.PSIsContainer){
                  Write-Host "COPY FOLDER : " $element.FullName
                  Copy-Item $element.FullName -Destination $targetFile
              }else{
                  Write-Host "COPY FILE : " $element.FullName
                  Copy-Item $element.FullName -Destination $targetFile
              }
          }
      }
  }
  
  function moveFiles($source,$destination,$days){
     Get-ChildItem -Path $source -Recurse | Where-Object {$_.LastWriteTime -lt (get-date).AddDays(-2)} | Move-Item -Destination $destination
  }
  
  CLS
  
  $Source = "C:\Users\tarasov_w\Downloads"
  $Destination = "C:\Users\tarasov_w\Desktop\ps_test"
  $LogFile = "C:\Users\tarasov_w\Desktop\$(get-date -format 'MMddyyyy').txt" 
  $Days = 1
  
  Start-Transcript $LogFile -noclobber
  
  Write-Host "Start..."
  
  removeFiles -source $Source -destination $Destination
  
  #copyFiles -source $Source -destination $Destination -days $Days
  
  moveFiles -source $Source -destination $Destination -days $Days
  
  Write-Host "Fertig!"
  </code></pre>
  
  <p><strong>UPDATE:</strong> </p>
  
  <pre><code>function compareFiles($source,$destination){
      $folderA = Get-ChildItem $source -Recurse
      $folderB = Get-ChildItem $destination -Recurse
  
      $diff = Compare-Object -ReferenceObject $folderA -DifferenceObject $folderB -PassThru
  
      foreach($element in $diff){
          $element_fullname = $element.FullName 
  
          if($element.PSIsContainer){
             # ????
          }
  
      }
  }
  </code></pre>