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,需要访 ...
随机推荐
- Notepad++ V6.9.0 中文绿色便携版
软件名称: Notepad++软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 3.4MB图片预览: 软件简介:Notepad中文版是一款非常有特色的编辑器,是开源 ...
- matlab mse函数
mse是检验神经网络算法的误差分析; mse是平均平方误差性能函数,是网络性能函数.平方误差就是指误差的平方.
- pickView不需要明确设置高度
pickView不用设置高度,若设置了,在iOS8.4.1上不会被填充,会造成没有把pickView高度设置成你想要的,但是布局其他地方的时候却会从你设置的地方开始,就会造成布局不紧挨着或者遮盖着的效 ...
- 自定义UICollectionView
1.创建一个UICollectionView工程,点击鼠标右侧按钮选择New File->Cocoa Class->点击Next,Class选项填写一个合理的名称,如:MyCollecti ...
- 常用CSS样式 持续更新
+ CSS + a标签 - 去除a标签下划线 a{ text-decoration:none; } - 未被访问状态下的a标签去除下划线 a:link{ text-decoration:none; } ...
- LeetCode OJ 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- 找最大重复次数的数和重复次数(C++ Pair)
Problem A: 第一集 你好,世界冠军 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 265 Solved: 50[Submit][Statu ...
- Centos7下安装pip
Linux 通过 pip 安装使用 Shadowsocks - CentOS 7 (06) Pip是安装Python包的工具,提供了安装.列举已安装包.升级以及卸载包的功能.Pip 是对easy_in ...
- malloc without free, what happens?
It's per-process. Once your process exits, the allocated memory is returned to the OS for use by oth ...
- MySQL慢日志查询全解析:从参数、配置到分析工具【转】
转自: MySQL慢日志查询全解析:从参数.配置到分析工具 - MySQL - DBAplus社群——围绕数据库.大数据.PaaS云,运维圈最专注围绕“数据”的学习交流和专业社群http://dbap ...