Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
|
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. |
||||
|
|
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:
|
|||||||||||||||
|
|
You may wish to check out The PowerShell Community Extensions (PSCX) which has cmdlets specifically for this. |
|||||||
|
|
Now in .NET Framework 4.5, there is a ZipFile class that you can use like 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. |
|||
|
|
|
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:
Try this:
Or even:
|
||||
|
|