這將壓縮。\在內容上。\ out.zip與System.IO.Packaging.ZipPackage下面的例子here
$zipArchive = $pwd.path + "\out.zip"
[System.Reflection.Assembly]::Load("WindowsBase,Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
$ZipPackage=[System.IO.Packaging.ZipPackage]::Open($zipArchive, [System.IO.FileMode]"OpenOrCreate", [System.IO.FileAccess]"ReadWrite")
$in = gci .\in | select -expand fullName
[array]$files = $in -replace "C:","" -replace "\\","/"
ForEach ($file In $files) {
$partName=New-Object System.Uri($file, [System.UriKind]"Relative")
$part=$ZipPackage.CreatePart($partName, "application/zip", [System.IO.Packaging.CompressionOption]"Maximum")
$bytes=[System.IO.File]::ReadAllBytes($file)
$stream=$part.GetStream()
$stream.Write($bytes, 0, $bytes.Length)
$stream.Close()
}
$ZipPackage.Close()
我認爲這解釋了您的選擇:http://richardspowershellblog.wordpress.com/2007/06/02/powershell-and-compressed-files/ – David
非常感謝!這是一個乾淨而簡單的解決方案。任何其他人可能會遇到此線索的指示。從下列網站下載PowerShell社區擴展: http://pscx.codeplex.com/downloads 提取文件,然後將目錄移至: C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ Modules。然後通過運行以下命令導入模塊: Import-Module Pscx – TechDawg270