Is it possible to create a zip archive using PowerShell?
相关问题
- How to Debug/Register a Permanent WMI Event Which
- How can I do variable substitution in a here-strin
- How to use a default value with parameter sets in
- Does powershell have a method_missing()?
- Invoking Mirth Connect CLI with Powershell script
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- C#调用PowerShell的问题
- EscapeDataString having differing behaviour betwee
- PowerShell Change owner of files and folders
- Command line escaping single quote for PowerShell
- Is there a simple way to pass specific *named* Pow
- How do I access an element with xpath with a names
- How to 'Grant Permissions' Using Azure Act
Edit two - This code is an ugly, ugly kluge from olden days. You do not want it.
This compresses the contents of
.\in
to.\out.zip
with System.IO.Packaging.ZipPackage following the example hereEdit: Unreliable for larger files, maybe >10mb, YMMV. Something to do with appdomain evidence and isolated storage. The friendlier .NET 4.5 approach works nicely from PS v3, but wanted more memory in my case. To use .NET 4 from PS v2, config files need an unsupported tweak.
Complete command-line Commands in Windows for Compressing and Extracting Directory is as follows:
For Compression:
For Extracting:
PowerShell v5.0 adds
Compress-Archive
andExpand-Archive
cmdlets. The linked pages have full examples, but the gist of it is:A pure PowerShell alternative that works with PowerShell 3 and .NET 4.5 (if you can use it):
Just pass in the full path to the zip archive you would like to create and the full path to the directory containing the files you would like to zip.
This is really obscure but works. 7za.exe is standalone version of 7zip and is available with install package.
If you head on over to CodePlex and grab the PowerShell Community Extensions, you can use their
write-zip
cmdlet.Since
you can go to PowerShell Gallery.