title: Zip/compress files modified in the last day
body: <p>I am really new to Powershell and scripting and would really appreciate if anyone is able to help. </p>
  
  <p>I am trying to create a PowerShell script which does the following to backup any changes on a daily basis in a set number of directories.</p>
  
  <ul>
  <li><p>Recursively find any new/modified files or directories from multiple preset locations only for the last 24 hours.</p></li>
  <li><p>Compress all the resulting entries in a zip file</p></li>
  <li>while keeping the folder structures </li>
  </ul>
  
  <p>I have managed to find get the first bit working using the following script:</p>
  
  <pre><code>Get-ChildItem $SRC | Where {$_.PsIsContainer} | foreach-object {
    Get-ChildItem $_ -Recurse -ErrorAction SilentlyContinue | 
    Where {$_.LastWriteTime -gt (get-date).AddDays(-1).date} |
    Select FullName, LastWriteTime, Mode | Sort LastWriteTime, Mode
  } &gt;&gt; C:\temp\LastModified-$TimeStamp.log
  </code></pre>
  
  <p>I have another script which zips up a given directory but I have been struggling to use the results from the script above to either robocopy the files to a location which I can then Zip or if there is a way to create a zip file without having to copy the files somewhere first without loosing the folder structure for each file?</p>
  
  <p>I have the following script which can Zip a given directory (but I need to zip multiple directories into one zip file unless I robocopy the files somewhere first &amp; how do I get robocopy to only copy only the files modified in the last 24 hours)</p>
  
  <pre><code>$Source =  'C:\Users\Downloads\RobocopyLocation\'
  $Destination = 'D:\OneDrive\'
  $TimeStamp = Get-Date -f yyyyMMdd_HHmmss
  $ZipName = "$Destination\$TimeStamp" + '_Backup.zip '
  
  Add-Type -Assembly "System.IO.Compression.FileSystem" ;
  [System.IO.Compression.ZipFile]::CreateFromDirectory($Source, $ZipName)
  </code></pre>
  
  <p>When I run the Script below I get and error message complaining about the path argument being null. </p>
  
  <pre><code>$F1 =  'C:\Users\Downloads\Folder A'
  $F2 =  'C:\Users\Downloads\Folder B'
  $F3 =  'C:\Users\Downloads\Folder C'
  $SrcFolders = ($F1, $F2, $F3); 
  $BackupDrive = "D:\OneDrive"
  $DestFolders = ("$BackupDrive\Folder A", "$BackupDrive\Folder B", "$BackupDrive\Folder C"); 
  $Destination = 'C:\Users\SysAdmin\Downloads\PLSWork\'
  $TimeStamp = Get-Date -f yyyyMMdd_HHmmss
  $ZipName = "$Destination\$TimeStamp" + '_Backup.zip '
  $Option = "{$_.PsIsContainer} | foreach-object { Get-ChildItem $_ -Recurse -ErrorAction SilentlyContinue | Where {$_.LastWriteTime -gt (get-date).AddDays(-1).date} | Select FullName, LastWriteTime, Mode | Sort LastWriteTime, Mode}"
  
  
  Foreach ($SrcFolders in (Get-ChildItem $SrcFolders | where $Option)){
  
  
  Add-Type -Assembly "System.IO.Compression.FileSystem" ;
  [System.IO.Compression.ZipFile]::CreateFromDirectory($SrcFolders, $ZipName)
  }
  </code></pre>