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. jms的初步认识

    (内容取自:http://itindex.net/detail/49721-jms-jms-%E5%BA%94%E7%94%A8) 什么是JMS? JMS即java消息服务, JMS通过消息的形式来降 ...

  2. word异常关闭,找到丢失的word

    Word模板路径位置 XP系统用户默认模板路径一般在 C:\Documents and Settings\Administrator\Application Data\Microsoft\Templa ...

  3. maven混淆Java代码

    Maven 环境下使用 proguard-maven-plugin 插件混淆你的源码 时间 2014-08-20 15:23:56 肖国颖的个人页面 原文  http://my.oschina.net ...

  4. Centos7 设置DNS 服务器

    在CentOS 7下,手工设置 /etc/resolv.conf 里的DNS,过了一会,发现被系统重新覆盖或者清除了.和CentOS 6下的设置DNS方法不同,有几种方式: 1.使用全新的命令行工具 ...

  5. Python基础篇-day3

    主要内容:字典 集合 文件处理 字符编码 1.字典dict简介dict就是key value值,索引有意义,数据无序 key定义规则:a:不可变--数字.字符串.元组(可变--列表.字典)b:不能重复 ...

  6. 数组按时间(字符串->Date)排序

    不说了 ,直接上代码.Talk is cheap , show me the code. NSArray *stortedArray = [wkSelf.dataArray sortedArrayUs ...

  7. gridControl 部分属性

    DEVexpress GridControl 属性设置 2013年11月22日 ⁄ 综合 ⁄ 共 18319字 ⁄ 字号 小 中 大 ⁄ 评论关闭 1. 如何解决单击记录整行选中的问题 View-&g ...

  8. Access to the path "Library\UnityAssemblies\UnityEngine.xml" is denied.

    这个问题基本上是重新打开UnityEditor,导入工程的时候VisualStudio还开着导致的. 解决方法是关掉Visual Studio,再重新打开.

  9. 【转载】将绿色版Tomcat服务添加到系统服务并设为开机运行

    转自: http://www.cnblogs.com/lan0725/archive/2009/11/04/1873859.html   运行cmd打开控制台,进入Tomat目录/bin文件夹,输入如 ...

  10. 开启真机的View Server引入HierarchyViewer/By写monkeyrunner自动化测试脚本

    其实相关文章网上也有不少了,不过在真机上开启View Server的中文文章好像只有一篇,前段时间按照这篇文章的内容,并结合英文源文去hack我的Nexus S(4.1.2)也走了一点弯路.现在总结一 ...