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的更多相关文章

  1. Compress a Folder/Directory via Perl5

    Compress a Folder/Directory via Perl5 tested in Windows, Mac OS X, Ubuntu16.04 #!/usr/bin/perl #压缩指定 ...

  2. powershell samples

    1,导出至EXCEL $arr =New-Object System.Collections.ArrayList $i = 1 $pstablelist = @(); $array =get-user ...

  3. 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 ...

  4. Managing IIS Log File Storage

    Managing IIS Log File Storage   You can manage the amount of server disk space that Internet Informa ...

  5. everything的使用

    https://www.voidtools.com/support/everything/searching/ 打开多个everything进程 https://www.voidtools.com/s ...

  6. Visual Basic 函数速查

    Calendar 常数 可在代码中的任何地方用下列常数代替实际值: 常数 值 描述 vbCalGreg 0 指出使用的是阳历. vbCalHijri 1 指出使用的是伊斯兰历法. Color 常数 可 ...

  7. Powershell script to install Windows Updates (msu) from folder

    ######################################################### # # Name: InstallWindowsUpdates.ps1 # Auth ...

  8. [PowerShell] Backup Folder and Files Across Network

    ## This Script is used to backup folder/files and delete the old backup files. ## Author: Stefanie # ...

  9. 在PowerShell中使用curl(Invoke-WebRequest)

    前言 习惯了windows的界面模式就很难转去命令行,甚至以命令行发家的git也涌现出各种界面tool.然而命令行真的会比界面快的多,如果你是一个码农. situation:接到需求分析bug,需要访 ...

随机推荐

  1. javascript焦点图自动缓冲滚动

    html中调用的js库,之前的随笔中有写,就不细说了,不明白的可以留言给我 <!DOCTYPE html> <html> <head> <meta chars ...

  2. 588. [NOIP1999] 拦截导弹

    588. [NOIP1999] 拦截导弹 ★  输入文件:missile.in  输出文件:missile.out  简单对比 时间限制:1 s 内存限制:128 MB 题目描述 某国为了防御敌国的导 ...

  3. IAR和Keil文件包含路径设置

    在模块化编程时,为一个模块单独设置头文件是必不可少的. 在两款主流编译器中,在引用模块函数时候,包含头文件路径是必须的,那么设置文件路径的准确性就显得尤为重要. 否则,编译器会报错,无法打开某某头文件 ...

  4. 对SNS网站现状和未来的一些想法——以我对人人网的体验为例

    现在对人人网越来越没有兴趣了,上面的照片.状态也越来越少了,反而是朋友圈里大家比较活跃. 我觉得在网上发内容的,至少是希望得到大家关注的,可是为什么人人越来越被大家嫌弃了呢? 人人上的消息越来越被淹没 ...

  5. HDU1577-WisKey的眼神

    Problem Description WisKey的眼镜有500多度,所以眼神不大好,而且他有个习惯,就是走路喜欢看着地(不是为了拣钱哦^_^),所以大家下次碰见他的时候最好主动打下招呼,呵呵.但是 ...

  6. 转:CSV Data Set Config 中文乱码问题

    从csv读取中文一直乱码. CSV Data Set Config的File encoding为GB2312,对应参数化文件编码也为GB2312,但读取出变量值一直为乱码,后发现是Allow quot ...

  7. mysql读写分离配置,利用mybatis实现,解释为什么dynamicDataSource不行

    之前发布了mysql主从配置的博客,配置完成之后,那么我们肯定要拿主从来做点什么. 我第一想到的就是mysql的读写分离,让读写分离之后可以大大的提供mysql的性能,比单纯用mysql主从做备份好很 ...

  8. Storm官方帮助手册翻译(上)

    Storm作为当前最流行的实时计算框架,自Twitter将其开源后就一直备受关注.由于其具有先天的稳定性以及便捷性,目前被许多大公司所采用,国外像雅虎.雅虎日本.Twitter.OOYALA.Spot ...

  9. 利用文本编辑器输入课堂上练习的Hello.java,并在JDK环境下编译和运行。

  10. Failed to load c++ bson extension, using pure JS version

    Failed to load c++ bson extension, using pure JS version npm install mongodbnpm install bson npm ins ...