Windows – How to you zip or unzip from the script using ONLY Windows’ built-in capabilities


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?

Best Solution

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('', 'bar'); }"

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