title: Powershell to Create a zip (or 7z) of each file in a folder then delete original file
body: <p>I have a folder with a Ton of iso images. I've found that a lot of the images have dummy data in them to reach the size of the original DVD. I can save an enormous amount of space by zipping them up.  I tried creating a batch file but it failed to work properly. </p>
  
  <p>So, I basically want it to create a .7z for each file in a folder, then delete the original file. </p>
  
  <p>Here's what I got. It zips the files but it fails on removable of the files afterwards. Can't figure out why:</p>
  
  <pre><code>function zipFiles()
   {
   dir *.iso| ForEach-Object { &amp; "7z.exe" a -mx9 $_.BaseName $_.Name } 
   }
  
  function delFiles()
   {
   dir *.iso| ForEach-Object { &amp; Remove-Item $_.BaseName $_.Name } 
   }
  
  zipFiles
  delFiles
  </code></pre>