title: Powershell 7zip compress and delete
body: <p>Ok so I'm still learning so please treat me like an idiot. 
  I have put together a script from various sources that will grab all files with given extension and age in a folder and use 7zip to compress the files. 
  What i also want to add is a way for the files that are successfully compressed to be deleted. 
  Now 7zip returns a message: "Everything is ok" after each file so i would guess there would be some way to take that and mark that file for deletion. </p>
  
  <p>My current code for compressing is below any help or tips on the deleting process would be awesome.
  Lucas</p>
  
  <pre><code>&lt;#  
  This script compresses all files with given extension in the set folder
  and add to daily archive ".zip" using 7izp.
  #&gt;
  
  
  #### 7 zip variable I got it from the below link 
  #### http://www.7-zip.org/ 
  # Alias for 7-zip
  if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw         "$env:ProgramFiles\7-Zip\7z.exe needed"}
    set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
  
  ############################################
  #### Variables 
  
  # The location of the files you want to compress
  $filePath = "D:\temp"
  
  # select extension, use .* for all
  $e = ".pdf"
  
  # Select in days how old a file must be to be processed.
  $d = 10
  
  #get the files in the folder the match requirements
  $ed = Get-ChildItem -Recurse -Path $filePath | Where-Object { _.Extension -eq "$e" -and $_.CreationTime –lt (Get-Date).AddDays(-$d) }
  
  #Gets current date for creating daily archive
  $date1 = Get-Date -Format "yyyyMMdd"
  
  #Gets current dir for using in archive folder name
  $path = Split-Path $filepath -Leaf
  
  
  ###########################################
  ############Function
  
  foreach ($file in $ed) {
                  $name = $file.name
                  $directory = $file.DirectoryName
                  $zipfile = "$path-$date1.zip"
                  sz a -tzip "$directory\$zipfile" "$directory\$name"     
              }
  
  ########### END OF SCRIPT ##########
  </code></pre>