# Friday, September 07, 2007
« Ubuntu - Dual Monitors | Main | Programmer?! No, I'm the "Deletor&q... »

Sometimes its just so hard to do the simple things with Windows, like unzip files without a 3rd party DLL.  After banging my head on this for a couple of hours I finally figured out a way to do it using Windows PowerShell and the Windows XP ZIP explorer extensions through the Shell32 COM interface.

function UnzipFile([string] $zipFile, [string] $destinationFolder)
{
    if(test-path($zipFile))
    {
        $shell = new-object -com Shell.Application
        $srcFolder = $shell.NameSpace($zipFile)
        $destFolder = $shell.NameSpace($destinationFolder)
        $items = $srcFolder.Items()
        $destFolder.CopyHere($items);
    }       
}

Friday, September 07, 2007 12:31:59 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  |  Related posts:
Recursively Deleting a Directory - Take 2

Wednesday, August 12, 2009 3:16:36 PM (GMT Standard Time, UTC+00:00)
Thanks. I add the following before '$destFolder = $shell.NameSpace($destinationFolder)':

if (-not (test-path($destinationFolder))) {
New-Item $destinationFolder -type directory
}

which creates the destination folder if it doesn't already exist.
Tim
Friday, December 04, 2009 7:22:10 PM (GMT Standard Time, UTC+00:00)
it works fine for unprotected file, what about the files which are password protected, it prompts for a password window , how can i embed that password in script
saurabh
Comments are closed.