How can you zip or unzip from the script using ONLY Windows' built-in capabilities?

Roee Gavirel picture Roee Gavirel · Jul 9, 2013 · Viewed 756.2k times · Source

In Windows you can zip some files by

right click → Send toCompressed (zipped) folder

And unzip by double clicking on the .zip file and extract the files.

Is there a way to apply those abilities from a script (.bat file) without the need to install any third-party software?

Answer

Jason Duffett picture Jason Duffett · Nov 10, 2014

To expand upon Steven Penny's PowerShell solution, you can incorporate it into a batch file by calling powershell.exe like this:

powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('foo.zip', 'bar'); }"

As Ivan Shilo said, this won't work with PowerShell 2, it requires PowerShell 3 or greater and .NET Framework 4.