There are many ways to compress a folder using powershell:
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
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
1) Download the extension from http://pscx.codeplex.com/
2) Unzip and put the folder in $PSHome\Modules
3) Execute cmdlet import-module pscx
This method requires administator permission
Compress a folder using powershell
原文:http://www.cnblogs.com/liangzi4000/p/6290280.html