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
For compression, I would use a library (7-Zip is good like Michal suggests).
If you install 7-Zip, the installed directory will contain
7z.exe
which is a console application.You can invoke it directly and use any compression option you want.
If you wish to engage with the DLL, that should also be possible.
7-Zip is freeware and open source.
I use this snippet to check my database backups folder for backup files not compressed yet, compress them using 7-Zip, and finally deleting the
*.bak
files to save some disk space. Notice files are ordered by length (smallest to biggest) before compression to avoid some files not being compressed.Here you can check a PowerShell script to backup, compress and transfer those files over FTP.
This should also work for compressing a single file without using a temp folder and using native .Net 4.5, converted from C# from this StackOverflow answer. It uses a nicer using syntax taken from here.
Usage:
ZipFiles -zipFilename output.zip -sourceFile input.sql -filename name.inside.zip.sql
Code:
Using:
If someone needs to zip a single file (and not a folder): http://blogs.msdn.com/b/jerrydixon/archive/2014/08/08/zipping-a-single-file-with-powershell.aspx
Here is the working code, zipping all files from a source folder and create a zip file in destination folder.
here is a native solution for ps v5, using cmdlet
Compress-Archive
Creating Zip files using PowerShell