Create zip files using PowerShell and 7Zip

This script is using 7zip for compression. The main purpose of this sciprt is to compress .bak files in to 7zip format. Currenlty it is compressing the .bak {sql backup} files. But if you want to compress the .Pdf or .doc files you can do it also with this script.  This script

4 Star
11,901 times
Add to favorites
E-mail Twitter Digg Facebook
  • temp 7z file created in C root
    1 Posts | Last post May 17, 2016
    • I use this script as windows schedule task on Database server to compress the backup file to 7z.But it also creates 7z file on C root and when i check the file it shows data of whole C start creating 7z for C drive.file creates without any name that is *.7z and i also checked 7zip temp folder set to "current" so temp files are created in current folder.
      what can be cause of creation of this 7z file?
  • ZipQuestion
    1 Posts | Last post February 22, 2016
    • Hello,I used the same code to zip my bak file , when the file small like 3MB ,it worked 200KB.But when the file big like 1.9GB, it does not worked 1.88GB.What's the problem? Or 7z is so ?
  • Assuming that 7-zip is in $env:ProgramFiles
    1 Posts | Last post January 29, 2015
    • Good solution. My only issue is that you assume that 7-Zip is installed in $env:ProgramFiles. The actual install location can quite easily be obtained by:
      $path = "HKLM:\Software\7-Zip","HKLM:\Software\Wow6432Node\7-Zip"|%{ if (Test-Path $_) { gp $_ } }|Select -First 1 -ExpandProperty Path
      This will return firstly the 64bit path (if there is one) or the 32bit path if there is one. Or $null if none.
      Thanks, Chris.
  • any validation to skip the file if already exists
    3 Posts | Last post November 14, 2012
    • The script works fine but i have one issue. I used to take daily backup if there any way that we can skip the zip process if the file already exists. i.e. on weekends i dont maually move the .bak files so it will zip the backup of saturday and sunday both can we put any condition where if .7z file exists it wil not zip them.
    • Hi Rakesh
      i will try to do that and i think that may be a little bit tricky to do.
    • You could just create each archive with a Unique identifier using the below:
      $JobGuid = [GUID]::NewGUID()
      and then use $jobguid in the naming convention for your compression jobs.
  • Move-Items or Add to One Archive
    2 Posts | Last post February 08, 2012
    • Is it possible to change this so it adds each files to the same archive?  I also tried adding
      sz a -t7z "$directory\$zipfile" "$directory\$name"
      move-item $directory\*.7z $bkpfldr\.Name
      and cannot get it to procees the move-item will complete the for loop and then end.
      Any ideas?  
      Many Thanks, this is a very simple and helpful solution for creating .7z archives.
      can u please explain a little bit more. the question is quite unclear to me:(
      Sorry ...