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 create a zip file in the same folder in which the orginal .bak file resides.
 
More info: http://newdelhipowershellusergroup.blogspot.com/2012/01/7zip-and-powershell.htm

Best Regards!

Aman Dhally 

Come and join my journey of 100 Days of Self Improvement programme: https://www.facebook.com/100DoSI or at www.amandhally.net   

MY PowerShell Blog : http://newdelhipowershellusergroup.blogspot.com/ 

MY Personal Website: www.amandhally.net

 

 
PowerShell
Edit|Remove
<#   
This script compress all .bak files {sql backups} in there cureent folder and make new .7zip file. 
  
http://newdelhipowershellusergroup.blogspot.com/2012/01/7zip-and-powershell.htm 
  
http://newdelhipowershellusergroup.blogspot.com 
  
#> 
 
 
#### 7 zip variable I got it from the below link  
 
#### http://mats.gardstad.se/matscodemix/2009/02/05/calling-7-zip-from-powershell/  
# 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  
 
$filePath = "C:\Users\aman.dhally\Desktop\Desktop-2\ASD\Test-3" 
 
$bak = Get-ChildItem -Recurse -Path $filePath | Where-Object { $_.Extension -eq ".bak" } 
 
########### END of VARABLES ################## 
 
foreach ($file in $bak) { 
                    $name = $file.name 
                    $directory = $file.DirectoryName 
                    $zipfile = $name.Replace(".bak",".7z") 
                    sz a -t7z "$directory\$zipfile" "$directory\$name"      
                } 
 
########### END OF SCRIPT ##########