title: Powershell move files and folders based on older than x days
body: <p>I am new to powershell and trying to learn a basic file move from one directory to another. My goal is to move files and folders that are over 18months old to cold storage folder run as a scheduled Task. I need to be able to easily modify it's directories to fit our needs. It needs to preserve the folder structure and only move files that fit the above parameters. I also need it to log everything it did so if something is off i know where.
  If I run this it just copies everything. If I comment out the %{Copy-Item... then it runs and lists only based on my parameters and logs it. Where am I going wrong or am I way off base?</p>
  <p>Yes it would be easy to use robocopy to do this but I want to use powershell and learn from it.</p>
  <pre><code>#Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear();
  #Clear-Host
  #Days older than
  $Days = &quot;-485&quot;
  #Path Variables
  $Sourcepath = &quot;C:\Temp1&quot;
  $DestinationPath = &quot;C:\Temp2&quot;
  #Logging
  $Logfile = &quot;c:\temp3\file_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).log&quot;
  
  #transcript logs all outputs to txt file 
  Start-Transcript -Path $Logfile -Append
  Get-ChildItem $Sourcepath -Force -Recurse | 
      Where-Object {$_.LastwriteTime -le (Get-Date).AddDays($Days)} | 
      % {Copy-Item -Path $Sourcepath -Destination $DestinationPath -Recurse -Force}
  Stop-Transcript
  </code></pre>