title: using 7zip to zip in powershell 5.0
body: <p>I have customized one powershell code to zip files older than 7 days from a source folder to a subfolder and then delete the original files from source after zipping is complete. The code is working fine with inbuilt Compress-Archive and Remove-Item cmdlets with less volume of files, but takes more time and system memory for a large volume of files. So, I'm working on a solution using 7zip instead as it's faster.</p>
  <p>Below script does zipping correctly but not following the condition of only files older than 7 days and deletes all the files from source folder. It should zip and delete only files older than 7 days.</p>
  <p>I have tried all possible ways to troubleshoot but no luck. Can anybody suggest possible solution?</p>
  <pre><code>if (-not (test-path &quot;$env:ProgramFiles\7-Zip\7z.exe&quot;)) {throw &quot;$env:ProgramFiles\7-Zip\7z.exe needed&quot;} 
  set-alias sz &quot;$env:ProgramFiles\7-Zip\7z.exe&quot; 
  
  $Date = Get-Date -format yyyy-MM-dd_HH-mm 
  $Source = &quot;C:\Users\529817\New folder1\New folder_2\&quot; 
  $Target = &quot;C:\Users\529817\New folder1\New folder_2\ARCHIVE\&quot;
  Get-ChildItem -path $Source | sz a -mx=9 -sdel $Target\$Date.7z $Source
  </code></pre>