Copy and archive directories and only files older than x Days
<p>I've search and i've tried. I know i'm not very good at powershell but i am starting to thing this isn't possible.</p>

<p>What I am trying to do is move all the contents of my C:\Data that are X days old and archive them. </p>

<p>Sounds easy.. BUT if
C:\data\Subject contains files from 2015 until Current. I only want to archive files that are X days old. so the new archived path would be C:\DataBackup and in there it would contain all Folders of C:\data but the only files in them would be X days old.. </p>

<p>This is what i was using to copy and archive the folders/files BUT it does not take into consideration the age.. IF it did,i would have it delete the files it moves from C:data as they are now backedup in C:\dataBackup</p>

<pre><code>$sourcePath = "C:\Data"   
$path = "C:\DataBackup"

$source = Get-ChildItem -Path $sourcePath -Directory

Add-Type -assembly "system.io.compression.filesystem"

Foreach ($s in $source)

 {

  $destination = Join-path -path $path -ChildPath "$($s.name).zip"


  If(Test-path $destination) {Remove-item $destination}


  [io.compression.zipfile]::CreateFromDirectory($s.fullname, $destination)}
</code></pre>