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,需要访 ...
随机推荐
- XP 右键扩展设置 1.0 免费绿色版
软件名称: xp右键扩展设置软件 1.0 免费绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP / Win2008软件大小: 57 ...
- 【CRC校验】学习笔记
#include<stdio.h> unsigned ]= { 0x01,0x02,0x03,0x04,0x05,0x06 }; ] = { 0x0000, 0x1021, 0x2042, ...
- 使用gulp构建nodejs,你只需要记住5个函数
gulp gulp是一个nodejs的streaming构建工具,所谓的streaming大致意思就是把构建流程想成一个个链接的管道(pipe). 为什么要这样做呢? 要解释原因,就不得不提到unix ...
- Webdriver实现对菜单栏的灵活切换功能,附上代码,类似的菜单栏切换可以自己封装
有时一级菜单下可能会有二级菜单,这时就需要对其下面的元素进行判断,如果使用webdriver原生的方法去获取未知的元素进行判断,显然是不可能的,因为webdriver本身就是基于明确的元素进行定位的, ...
- wordpress建站过程2——结构
开始wordpress之前,我们需要了解,wordpress的结构和调用方式. 当一个wordpress开始之后,他会读取[当前主题]的index.php.所以一旦主题切换了,它读的就是其他主题的in ...
- 在自学php的路上不知道怎么走!!
在自学php的路上不知道怎么走!! 真希望有人给我指点一二!!!
- js函数大全(2)
原文地址:http://phperbar.blog.163.com/blog/static/162596182201032935815391/ 1.常规函数 javascript常规函数包括以下9个函 ...
- LeetCode OJ 235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...
- jsp第1讲(上集)
jsp讲解框架 (一)Java EE核心十三种技术介绍 (二)Java EE程序员修炼成精的法门 (三)jsp版本的用户管理系统演示 (四)jsp概述 (五)jsp的运行原理 (六)jsp版的计算器 ...
- word转pdf swf 在线预览
来源:http://www.cnblogs.com/wuhenke/archive/2010/08/01/1789750.html 之前在项目中研究使用了一套word转PDF,然后将PDF转成SWF的 ...