When I developed automssqlbackup, one of the key features was to optionally zip the generated database backup file.
I found solutions like this which essentially create an empty zip archive, then create a Shell.Application object to access this archive, and add files using the CopyHere or MoveHere methods of that object.
CopyHere and MoveHere execute asynchronously. The caller does not receive any feedback when the operation is complete, and has to query the number of files in the archive to find out.
Since these effects showed up soon after I tested my script on different machines, it was clear that zipping had to be solved more reliably: using SharpZipLib.
Quick and easy, but with a drawback: the filenames are stored including their original path information.
$filenamedir is the base directory of all files to be included in the zip, followed by the recursive flag.
The final parameter is a bit tricky: it is named FileFilter, but it is not a DOS-like filter (“*.*”), but rather a regular expression being evaluated on each file. In the example above, all files with extension .bak are selected.
This entry was posted on Wednesday, February 11th, 2009 at 20:51 and is filed under automssqlbackup, Powershell.	You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
@stej: I used SharpZipLib before in another project (C#), it was easy to integrate, and it’s a plain .Net solution.
Sure, np 🙂 I was just curious, because the commmand line zip is much faster for me.
Fyi: I have found a post that compares zipping in .net: http://blog.vyvojar.cz/topas/archive/2009/08/04/net-a-zip-komprese.aspx It is in czech, but you can see other zipping tools at least (in the table).
What if I want to tell the script to zip just the file older than 15 days? Right now, I have to move the files I want to zip into a folder, and then zip them.