Compress a folder using powershell
There are many ways to compress a folder using powershell:
Method 1: Using System.IO.Compression and System.IO.Compression.FileSystem
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory($source_WebPortal, $destination_WebPortal,[System.IO.Compression.CompressionLevel]::Fastest,$True)
This method requires .NET Framework 4.5 installed
参考链接:https://gist.github.com/stefanteixeira/0428e8ade6be09d94b90
Method 2: Using pure Powershell script
function Add-Zip
{
param([string]$zipfilename) if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
} $shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename) foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Start-sleep -milliseconds 200
}
} dir $tempFolder\*.* -Recurse | add-Zip $zipFile
This method can be run at powershell 2.0 and .NET Framework 4.0
参考链接:https://blogs.msdn.microsoft.com/daiken/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget/
Method 3: Using PowerShell Community Extensions
1) Download the extension from http://pscx.codeplex.com/
2) Unzip and put the folder in $PSHome\Modules
3) Execute cmdlet import-module pscx
4) Use the cmdlet write-zip to compress file
This method requires administator permission
参考链接:http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell
Compress a folder using powershell的更多相关文章
- Compress a Folder/Directory via Perl5
Compress a Folder/Directory via Perl5 tested in Windows, Mac OS X, Ubuntu16.04 #!/usr/bin/perl #压缩指定 ...
- powershell samples
1,导出至EXCEL $arr =New-Object System.Collections.ArrayList $i = 1 $pstablelist = @(); $array =get-user ...
- AX7: How to deploy a Package
A. Using LCS services. B. Manual using command prompt. Here I’ll show using command prompt, as I fou ...
- Managing IIS Log File Storage
Managing IIS Log File Storage You can manage the amount of server disk space that Internet Informa ...
- everything的使用
https://www.voidtools.com/support/everything/searching/ 打开多个everything进程 https://www.voidtools.com/s ...
- Visual Basic 函数速查
Calendar 常数 可在代码中的任何地方用下列常数代替实际值: 常数 值 描述 vbCalGreg 0 指出使用的是阳历. vbCalHijri 1 指出使用的是伊斯兰历法. Color 常数 可 ...
- Powershell script to install Windows Updates (msu) from folder
######################################################### # # Name: InstallWindowsUpdates.ps1 # Auth ...
- [PowerShell] Backup Folder and Files Across Network
## This Script is used to backup folder/files and delete the old backup files. ## Author: Stefanie # ...
- 在PowerShell中使用curl(Invoke-WebRequest)
前言 习惯了windows的界面模式就很难转去命令行,甚至以命令行发家的git也涌现出各种界面tool.然而命令行真的会比界面快的多,如果你是一个码农. situation:接到需求分析bug,需要访 ...
随机推荐
- 【java学习】Servlet简单的表单程序(一)
此文用于java学习,在此小记. 在此小Demo中使用到了Servlet,所以有必要了解一下Servlet的相关知识.(Servlet的相关知识摘抄自http://blog.csdn.net/jiuq ...
- Openlayer 3 的画图测量面积
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDU 2722 Here We Go(relians) Again (spfa)
Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/ ...
- HttpClient的get和post方式提交数据的使用
/** * Http工具类 */ public class HttpUtil { // 创建HttpClient对象 public static HttpClient httpClient = new ...
- TD8.0迁移到QC9.2,自动迁移失败,手动迁移
源机器A:TD8.0+SQLServer2000目标机器B:QC9.2+SQLServer2000 一:自动迁移,1.在A在A上安装QC迁移工具,然后在B中点击TOOLS>>Migrati ...
- lldp中与snmp相关内容agentx
struct lldpd { int g_snmp; struct event *g_snmp_timeout; void *g_snmp_fds; char *g_snmp_agen ...
- storm 使用过程中遇到的问题
1 bolt不停重启,excutor无法启动. nimbus日志类似如下(), 2014-03-12 10:55:06 b.s.d.nimbus [INFO] Executor MITAS3-74-1 ...
- 妙用transform
往前移动 transform.Translate transform.Translate( transform.up* speed*Time.deltaTime , Space.World); 移动t ...
- 被非技术瓶颈阻挡了,没钱买Mac,挣扎ing
最近一直没来写博客,因为一直在找刷盘子.服务生.看店的工. 已经找到,主要因为前阵子天不热,所以酒馆的顾客不多.现在好了. 只好买个Mac mini,看了很多帖子,也只好暂时折中这样了.Mac买不起. ...
- Error configuring application listener of class 报错 解决
Error configuring application listener of class 次错误是由于工程没有贬义Class文件造成的,clean一下编译一下工程,clean之后进入项目目录查看 ...