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. eclipse和tomcat整合之后每次发布server.xml被修改(转)

    eclipse每次发布,server.xml和context.xml总是被还原 直接找到eclispse工程下的server工程,把里面的相应的server.xml和context.xml修改了即可, ...

  2. sql 将表B中不存在表A的数据 插入到表A中

    insert into tableA select * from tableB b where not exists(select 1 from tableA a where a.id = b.id) ...

  3. 常用的css

    产品鼠标经过加边框效果 .productsCol:hover { box-shadow: 0 0 0 3px #333333 inset; transition: all 0.2s ease 0s; ...

  4. Chapter 1 First Sight——34

    "Was that the boy I sat next to in Biology?" I asked artlessly. 你是生物课坐在我旁边的男生吗?我天真烂漫的问道. & ...

  5. mybatis 总结(1)

    注意事项 1.在使用type 和JavaType 以及reusltType ,ofType的时候一定要设置"别名"在mybatis.cfg.xml中设置 <typeAlias ...

  6. mvc UrlHelper

    何谓Helper,其实就是在View中为了实现一些灵活功能而写的方法组. 其实ASP.NET MVC的View是Aspx的页面,本身可以声明定义方法,那为什么要有Helper呢? 其实无非是将界面与逻 ...

  7. iOS 开发者旅途中的指南针 - LLDB 调试技术

    文章转载于:iOS 开发者旅途中的指南针 - LLDB 调试技术 今天给大家介绍的内容,无关乎任何功能性开发技术,但又对开发的效率影响至深,这就是调试技术. 何为调试呢,比如我们用 print 函数在 ...

  8. Chrome不支持showModalDialog模态对话框和无法返回returnValue的问题

    父窗体部分js代码: var returnValue = window.showModalDialog("son.html ", window); //for chrome if ...

  9. unable to connect to :5555

    有可能批处理文件用的adb和eclipse的adb不兼容.把你的批处理文件用的adb换成eclipse的adb就可以了: 运行结果:

  10. Linux下 Unison 实现文件双向同步

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://hx100.blog.51cto.com/44326/612301 一.Uniso ...