I find the simplest solution to just use infozip binaries which I have used for years and use in a UNIX environment.
PS> zip -9r ../test.zip *
PS> cd ..
PS> unzip -t test.zip Archive: test.zip
testing: LinqRepository/ OK
testing: LinqRepository/ApplicationService.cs OK
testing: LinqRepository/bin/ OK
...
No errors detected in compressed data of test.zip.
It would be straighforward to put a powershell wrapper around the text output but in practice I never need that so I haven't bothered.
I also like Info-ZIP (the Zip engine found in most other Zip utilities) and 7-Zip, another favorite which has both a GUI and command line Zip utility. The point being, there are some good command-line utilities that will work for most PowerShell tasks.
There are some tricks to running command line utilities that were not built with PowerShell in mind:
Running an executable that starts with a number in the name, preface it with an Ampersand (&).
&7zip.exe
Wrap each token, the utility is expecting to see from the command line, in quotes.
&"c:\path with space\SomeCommand.exe" "/parameter2" "/parameter2" "parameter2's Value" "Value2 `" with a quote"
This is how you can do it purely from Powershell without any external tools. This unzips a file called test.zip onto the current working directory:
Now in .NET Framework 4.5, there is a ZipFile class that you can use like this:
DotNetZip will allow you to do this from PowerShell. It is not a one-liner, but the library will allow you to write the PowerShell script you need.
You can also use the COM interface, see Compress Files with Windows PowerShell then package a Windows Vista Sidebar Gadget.
Googling "zip powershell" or "unzip powershell" might also turn up useful results.
I know this is a very old question, but I just saw it linked on Twitter on figured I'd post a current answer.
PowerShell 5, currently available on Windows 10 or via the Windows Management Framework 5 Production Preview, comes with two built-in cmdlets for 'zipping' and 'unzipping':
You may wish to check out The PowerShell Community Extensions (PSCX) which has cmdlets specifically for this.
I find the simplest solution to just use infozip binaries which I have used for years and use in a UNIX environment.
It would be straighforward to put a powershell wrapper around the text output but in practice I never need that so I haven't bothered.
http://www.info-zip.org/
I also like Info-ZIP (the Zip engine found in most other Zip utilities) and 7-Zip, another favorite which has both a GUI and command line Zip utility. The point being, there are some good command-line utilities that will work for most PowerShell tasks.
There are some tricks to running command line utilities that were not built with PowerShell in mind:
Running an executable that starts with a number in the name, preface it with an Ampersand (&).
&7zip.exe
Wrap each token, the utility is expecting to see from the command line, in quotes.
&"c:\path with space\SomeCommand.exe" "/parameter2" "/parameter2" "parameter2's Value" "Value2 `" with a quote"
Try this:
Or even:
James Holwell I like your answer but I expanded it a little bit
WinRAR can work in CMD mode accepting arguments
The ionic approach rocks:
https://dotnetzip.codeplex.com/wikipage?title=PS-Examples
supports passwords, other crypto methods, etc.