How can you zip or unzip from the script using ONLY Windows' built-in capabilities?
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.
If you have Java installed, you can compress to a ZIP archive using the jar
command:
jar -cMf targetArchive.zip sourceDirectory
c = Creates a new archive file.
M = Specifies that a manifest file should not be added to the archive.
f = Indicates target file name.
PowerShell 5.0
From Microsoft.PowerShell.Archive
you can use:
Compress-Archive
-
Expand-Archive
E.g.:
-
Create
result.zip
from the entireTest
folder:Compress-Archive -Path C:\Test -DestinationPath C:\result
-
Extract the content of
result.zip
in the specifiedTest
folder:Expand-Archive -Path result.zip -DestinationPath C:\Test