Powershell SevenZipCompressor

Oct 12, 2011 at 6:22 PM
Edited Oct 12, 2011 at 6:28 PM

I have PowerShell create the object like:

add-type -path c:\pathtodll\SevenZipSharp.dll
$zip = new-object SevenZip.SevenZipCompressor

$zip.CompressionLevel = "Ultra"
$zip.PreserveDirectoryRoot = "True"
$zip.ArchiveFormat = "zip"
$zip.CompressionMethod = "LZMA"

 I call the zip process like:


This allows me to create the $zip object and make the settings have a great compression (ultra & LZMA) with a very accessible format container (zip). This seems to work fine with the testing on the servers that I have done.  I hope this helps other PowerShell users out there.

Note: Make sure that you have the 7z.dll file in the same directory as the SevenZipSharp.dll file.

2nd Note: I actually reference my dlls like this:

add-type -path (Join-Path $PWD.Path dll\SevenZipSharp.dll)

I like to keep my scripts modular.  So, I keep the backup script in its own folder and then put the dll files in a sub dll folder.  When the script is launched, the $PWD is the 'PowerShell working directory'.  So, I can move my folder around and PowerShell can figure out where the dll folder is.