Monday, September 16, 2013

How to unzip files in Windows 7 and Windows 2008 natively

Photo by: Klafubra

Unix systems have had native unzipping programs for the last few decades that are easily accessible from scripts.  Now Microsoft has darkened the door of the party.
Instead of downloading 7zip or WinZip, you can now natively unzip files provided your server has the latest software.  You need .Net 4.5 and PowerShell 3.0, and then everything is unicorns and rainbows.
In PowerShell scripts to unzip file "$zipFile" into directory "$targetFolder" you can do this:
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $targetFolder)

No comments: