เป็นไปได้หรือไม่ที่จะสร้างไฟล์ zip โดยใช้ PowerShell
เป็นไปได้หรือไม่ที่จะสร้างไฟล์ zip โดยใช้ PowerShell
คำตอบ:
ถ้าคุณมุ่งหน้าไปยัง CodePlex และคว้าส่วนขยายชุมชน PowerShellคุณสามารถใช้write-zipcmdlet ของพวกเขาได้
ตั้งแต่
CodePlex อยู่ในโหมดอ่านอย่างเดียวเพื่อเตรียมการปิดระบบ
คุณสามารถไปที่PowerShell แกลลอรี่
write-zip [input file/folder] [output file]
                    ทางเลือก PowerShell ล้วนที่ใช้งานได้กับ PowerShell 3 และ. NET 4.5 (หากคุณสามารถใช้งานได้):
function ZipFiles( $zipfilename, $sourcedir )
{
   Add-Type -Assembly System.IO.Compression.FileSystem
   $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
   [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
        $zipfilename, $compressionLevel, $false)
}
เพียงผ่านเส้นทางแบบเต็มไปยังไฟล์ zip ที่คุณต้องการสร้างและเส้นทางแบบเต็มไปยังไดเรกทอรีที่มีไฟล์ที่คุณต้องการจะซิป
PowerShell v5.0 เพิ่มCompress-ArchiveและExpand-Archivecmdlets หน้าที่เชื่อมโยงมีตัวอย่างเต็มรูปแบบ แต่ส่วนสำคัญของมันคือ:
# Create a zip file with the contents of C:\Stuff\
Compress-Archive -Path C:\Stuff -DestinationPath archive.zip
# Add more files to the zip file
# (Existing files in the zip file with the same name are replaced)
Compress-Archive -Path C:\OtherStuff\*.txt -Update -DestinationPath archive.zip
# Extract the zip file to C:\Destination\
Expand-Archive -Path archive.zip -DestinationPath C:\Destination
              Compress-Archiveคำอธิบายย่อหน้าที่ 2 : "... ขนาดไฟล์สูงสุดที่คุณสามารถบีบอัดได้โดยใช้ Compress-Archive ในปัจจุบันคือ 2 GB นี่เป็นข้อ จำกัด ของ API พื้นฐาน" อย่างไรก็ตามหากคุณใช้System.IO.Compression.ZipFileคุณสามารถข้ามข้อ จำกัด นี้ได้
                    System.IO.Compression.ZipFileได้รับการสืบทอดมาจาก ถ้า. NET Framework ที่คุณใช้ไม่มีขีด จำกัด นี้ CmdLet ไม่ควรถึงขีด จำกัด นี้ ฉันตรวจสอบในรหัส
                    -OutputPathพารามิเตอร์
                    วิธีดั้งเดิมที่มี. NET 4.5 Framework ล่าสุด แต่ไม่มีฟีเจอร์ทั้งหมด:
การสร้าง:
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory("c:\your\directory\to\compress", "yourfile.zip") ;
การสกัด:
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::ExtractToDirectory("yourfile.zip", "c:\your\destination") ;
ตามที่กล่าวไว้คุณสมบัติโดยสิ้นเชิงน้อยดังนั้นอย่าคาดหวังว่าการเขียนทับธง
ปรับปรุง: ดูด้านล่างสำหรับนักพัฒนาอื่น ๆ ที่มีการขยายตัวในช่วงหลายปี ...
ติดตั้ง 7zip (หรือดาวน์โหลดรุ่นบรรทัดคำสั่งแทน) และใช้วิธี PowerShell นี้:
function create-7zip([String] $aDirectory, [String] $aZipfile){
    [string]$pathToZipExe = "$($Env:ProgramFiles)\7-Zip\7z.exe";
    [Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory", "-r";
    & $pathToZipExe $arguments;
}
คุณสามารถโทรแบบนี้:
create-7zip "c:\temp\myFolder" "c:\temp\myFolder.zip"
              & "C:\Program Files\7-Zip\7z.exe" a -tzip ($file.FullName+".zip") $file.FullName
                    ล็อตได้เปลี่ยนไปตั้งแต่คำตอบเริ่มต้นถูกโพสต์ นี่คือตัวอย่างล่าสุดบางส่วนที่ใช้คำสั่งCompress-Archive
คำสั่งเพื่อสร้างไฟล์เก็บถาวรใหม่Draft.zipโดยการบีบอัดสองไฟล์Draftdoc.docxและdiagram2.vsdระบุโดยPathพารามิเตอร์ ระดับการบีบอัดที่ระบุสำหรับการดำเนินการนี้คือระดับสูงสุด
Compress-Archive -Path C:\Reference\Draftdoc.docx, C:\Reference\Images\diagram2.vsd -CompressionLevel Optimal -DestinationPath C:\Archives\Draft.Zip
คำสั่งเพื่อสร้างไฟล์เก็บถาวรใหม่Draft.zipโดยการบีบอัดสองไฟล์Draft doc.docxและDiagram [2].vsdระบุโดยLiteralPathพารามิเตอร์ ระดับการบีบอัดที่ระบุสำหรับการดำเนินการนี้คือระดับสูงสุด
Compress-Archive -LiteralPath 'C:\Reference\Draft Doc.docx', 'C:\Reference\Images\Diagram [2].vsd'  -CompressionLevel Optimal -DestinationPath C:\Archives\Draft.Zip
คำสั่งเพื่อสร้างไฟล์เก็บถาวรใหม่Draft.zipในC:\Archivesโฟลเดอร์ ไฟล์เก็บถาวรใหม่มีทุกไฟล์ในโฟลเดอร์C: \ Referenceเนื่องจากมีการใช้อักขระไวด์การ์ดแทนชื่อไฟล์เฉพาะในพารามิเตอร์Path
Compress-Archive -Path C:\Reference\* -CompressionLevel Fastest -DestinationPath C:\Archives\Draft
คำสั่งสร้างไฟล์เก็บถาวรจากทั้งโฟลเดอร์ C:\Reference
Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft
PowerShell ผนวก.zipส่วนขยายเข้ากับชื่อไฟล์โดยอัตโนมัติ
แก้ไขสอง - รหัสนี้น่าเกลียด kluge น่าเกลียดจากสมัยก่อน คุณไม่ต้องการมัน
สิ่งนี้บีบอัดเนื้อหาของ.\inถึง.\out.zipด้วย System.IO.Packaging.ZipPackage ทำตามตัวอย่างที่นี่
$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()
แก้ไข: ไม่น่าเชื่อถือสำหรับไฟล์ขนาดใหญ่อาจ> 10mb, YMMV สิ่งที่ ต้องทำกับหลักฐานโดเมนแอปและพื้นที่เก็บข้อมูลแยกต่างหาก วิธี. NET 4.5 ที่เป็นมิตรกว่านี้ทำงานได้ดีจาก PS v3 แต่ต้องการหน่วยความจำเพิ่มเติมในกรณีของฉัน หากต้องการใช้ .NET 4 จาก PS v2, config ไฟล์ต้องไม่สนับสนุน การปรับแต่ง
ให้ตัวเลือกอื่นด้านล่าง นี่จะบีบอัดโฟลเดอร์แบบเต็มและจะเขียนไฟล์เก็บถาวรไปยังเส้นทางที่กำหนดพร้อมชื่อที่กำหนด
ต้องใช้. NET 3 ขึ้นไป
Add-Type -assembly "system.io.compression.filesystem"
$source = 'Source path here'    
$destination = "c:\output\dummy.zip"
If(Test-path $destination) {Remove-item $destination}
[io.compression.zipfile]::CreateFromDirectory($Source, $destination)
              นี่คือโซลูชันดั้งเดิมสำหรับ PowerShell v5 โดยใช้ cmdlet Compress-Archive การสร้างไฟล์ Zip โดยใช้ PowerShellPowerShell
ดูเอกสาร Microsoft สำหรับการ บีบอัดเอกสารเก่าการบีบอัด-Archive
ตัวอย่างที่ 1:
Compress-Archive `
    -LiteralPath C:\Reference\Draftdoc.docx, C:\Reference\Images\diagram2.vsd `
    -CompressionLevel Optimal `
    -DestinationPath C:\Archives\Draft.Zip
ตัวอย่างที่ 2:
Compress-Archive `
    -Path C:\Reference\* `
    -CompressionLevel Fastest `
    -DestinationPath C:\Archives\Draft
ตัวอย่างที่ 3:
Write-Output $files | Compress-Archive -DestinationPath $outzipfile
              สำหรับการบีบอัดฉันจะใช้ไลบรารี่ (7-Zip ก็ดีเหมือนมีคาลแนะนำไล )
หากคุณติดตั้ง7-Zipไดเรกทอรีที่ติดตั้งจะมี7z.exeแอพพลิเคชั่นคอนโซล
คุณสามารถเรียกใช้โดยตรงและใช้ตัวเลือกการบีบอัดใด ๆ ที่คุณต้องการ
หากคุณต้องการมีส่วนร่วมกับ DLL ก็ควรจะเป็นไปได้เช่นกัน 
7-Zip เป็นฟรีแวร์และโอเพ่นซอร์ส
เกี่ยวกับSystem.IO.Packaging.ZipPackageอะไร
มันต้องการ. NET 3.0 หรือสูงกว่า
#Load some assemblys. (No line break!)
[System.Reflection.Assembly]::Load("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
#Create a zip file named "MyZipFile.zip". (No line break!)
$ZipPackage=[System.IO.Packaging.ZipPackage]::Open("C:\MyZipFile.zip",
   [System.IO.FileMode]"OpenOrCreate", [System.IO.FileAccess]"ReadWrite")
#The files I want to add to my archive:
$files = @("/Penguins.jpg", "/Lighthouse.jpg")
#For each file you want to add, we must extract the bytes
#and add them to a part of the zip file.
ForEach ($file In $files)
{
   $partName=New-Object System.Uri($file, [System.UriKind]"Relative")
   #Create each part. (No line break!)
   $part=$ZipPackage.CreatePart($partName, "",
      [System.IO.Packaging.CompressionOption]"Maximum")
   $bytes=[System.IO.File]::ReadAllBytes($file)
   $stream=$part.GetStream()
   $stream.Write($bytes, 0, $bytes.Length)
   $stream.Close()
}
#Close the package when we're done.
$ZipPackage.Close()
ผ่านAnders Hesselbom
ทำไมไม่มีใครดูเอกสารประกอบ ?? มีวิธีการที่ได้รับการสนับสนุนในการสร้างไฟล์ zip ที่ว่างเปล่าและเพิ่มแต่ละไฟล์ที่สร้างไว้ในไลบรารี NET 4.5 เดียวกันทุกคนกำลังอ้างอิง
ดูตัวอย่างโค้ดด้านล่าง:
# Load the .NET assembly
Add-Type -Assembly 'System.IO.Compression.FileSystem'
# Must be used for relative file locations with .NET functions instead of Set-Location:
[System.IO.Directory]::SetCurrentDirectory('.\Desktop')
# Create the zip file and open it:
$z = [System.IO.Compression.ZipFile]::Open('z.zip', [System.IO.Compression.ZipArchiveMode]::Create)
# Add a compressed file to the zip file:
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($z, 't.txt', 't.txt')
# Close the file
$z.Dispose()
ฉันขอแนะนำให้คุณเรียกดูเอกสารหากคุณมีคำถามใด ๆ
นี่เป็นสิ่งที่คลุมเครือจริงๆ แต่ใช้ได้ผล 7za.exeเป็น 7zip เวอร์ชันสแตนด์อโลนและสามารถใช้ได้กับแพ็คเกจการติดตั้ง
# get files to be send
$logFiles = Get-ChildItem C:\Logging\*.* -Include *.log | where {$_.Name -match $yesterday} 
foreach ($logFile in $logFiles)
{
    Write-Host ("Processing " + $logFile.FullName)
    # compress file
    & ./7za.exe a -mmt=off ($logFile.FullName + ".7z") $logFile.FullName
}
              หากมีคนต้องการซิปไฟล์เดียว (ไม่ใช่โฟลเดอร์): http://blogs.msdn.com/b/jerrydixon/archive/2014/08/08/zipping-a-single-file-with-powershell.aspx
[CmdletBinding()]
Param(
     [Parameter(Mandatory=$True)]
     [ValidateScript({Test-Path -Path $_ -PathType Leaf})]
     [string]$sourceFile,
     [Parameter(Mandatory=$True)]
     [ValidateScript({-not(Test-Path -Path $_ -PathType Leaf)})]
     [string]$destinationFile
) 
<#
     .SYNOPSIS
     Creates a ZIP file that contains the specified innput file.
     .EXAMPLE
     FileZipper -sourceFile c:\test\inputfile.txt 
                -destinationFile c:\test\outputFile.zip
#> 
function New-Zip
{
     param([string]$zipfilename)
     set-content $zipfilename 
          ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
     (dir $zipfilename).IsReadOnly = $false
}
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 500
     }
}
dir $sourceFile | Add-Zip $destinationFile
              นี่คือรหัสการทำงานซิปไฟล์ทั้งหมดจากโฟลเดอร์ต้นทางและสร้างไฟล์ซิปในโฟลเดอร์ปลายทาง
    $DestZip="C:\Destination\"
    $Source = "C:\Source\"
    $folder = Get-Item -Path $Source
    $ZipTimestamp = Get-Date -format yyyyMMdd-HHmmss;
    $ZipFileName  = $DestZip + "Backup_" + $folder.name + "_" + $ZipTimestamp + ".zip" 
    $Source
    set-content $ZipFileName ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 
    # Wait for the zip file to be created.
    while (!(Test-Path -PathType leaf -Path $ZipFileName))
    {    
        Start-Sleep -Milliseconds 20
    } 
    $ZipFile = (new-object -com shell.application).NameSpace($ZipFileName)
    Write-Output (">> Waiting Compression : " + $ZipFileName)       
    #BACKUP - COPY
    $ZipFile.CopyHere($Source) 
    $ZipFileName
    # ARCHIVE
    Read-Host "Please Enter.."
              function Zip-File
    {
    param (
    [string]$ZipName,
    [string]$SourceDirectory 
    )
       Add-Type -Assembly System.IO.Compression.FileSystem
       $Compress = [System.IO.Compression.CompressionLevel]::Optimal
       [System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectory,
            $ZipName, $Compress, $false)
    }
หมายเหตุ: 
ZipName: เส้นทางแบบเต็มของไฟล์ซิปที่คุณต้องการสร้าง
SourceDirectory: พา ธ เต็มไปยังไดเรกทอรีที่มีไฟล์ที่คุณต้องการซิป
นี่คือคำตอบของ sonjz รุ่นปรับปรุงเล็กน้อยมันเพิ่มตัวเลือกการเขียนทับ
function Zip-Files(
        [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$false)]
        [string] $zipfilename,
        [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$false)]
        [string] $sourcedir,
        [Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$false)]
        [bool] $overwrite)
{
   Add-Type -Assembly System.IO.Compression.FileSystem
   $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
    if ($overwrite -eq $true )
    {
        if (Test-Path $zipfilename)
        {
            Remove-Item $zipfilename
        }
    }
    [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false)
}
              นี้ยังควรทำงานสำหรับการบีบอัดไฟล์เดียวโดยไม่ต้องใช้โฟลเดอร์ชั่วคราวและใช้พื้นเมืองสุทธิ 4.5 แปลงจาก C # จาก StackOverflow นี้คำตอบ มันใช้ nicer โดยใช้ไวยากรณ์ที่นำมาจากที่นี่ที่นี่
การใช้งาน:
ZipFiles -zipFilename output.zip -sourceFile input.sql -filename name.inside.zip.sql
รหัส:
function ZipFiles([string] $zipFilename, [string] $sourceFile, [string] $filename)
{
    $fullSourceFile = (Get-Item -Path "$sourceFile" -Verbose).FullName
    $fullZipFile = (Get-Item -Path "$zipFilename" -Verbose).FullName
    Add-Type -AssemblyName System.IO
    Add-Type -AssemblyName System.IO.Compression
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    Using-Object ($fs = New-Object System.IO.FileStream($fullZipFile, [System.IO.FileMode]::Create)) {
         Using-Object ($arch = New-Object System.IO.Compression.ZipArchive($fs, [System.IO.Compression.ZipArchiveMode]::Create)) {
             [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($arch, $fullSourceFile, $filename)
        }
    }
}
โดยใช้:
function Using-Object
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [AllowEmptyCollection()]
        [AllowNull()]
        [Object]
        $InputObject,
        [Parameter(Mandatory = $true)]
        [scriptblock]
        $ScriptBlock
    )
    try
    {
        . $ScriptBlock
    }
    finally
    {
        if ($null -ne $InputObject -and $InputObject -is [System.IDisposable])
        {
            $InputObject.Dispose()
        }
    }
}
              shell.applicationธุรกิจหรือ 7-Zip / โปรแกรมอรรถประโยชน์อื่น ๆ ฉันชอบUsing-Objectฟังก์ชั่นด้วยแม้ว่าฉันจะใช้วิธีสั้นลงและรวดเร็ว
                    
ฉันใช้ตัวอย่างนี้เพื่อตรวจสอบโฟลเดอร์สำรองฐานข้อมูลของฉันสำหรับไฟล์สำรองที่ยังไม่บีบอัดบีบอัดโดยใช้ 7-Zip และในที่สุดก็ลบ*.bakไฟล์เพื่อประหยัดพื้นที่ดิสก์บางส่วน ไฟล์ประกาศจะเรียงลำดับตามความยาว (น้อยที่สุดไปหามากที่สุด) ก่อนการบีบอัดเพื่อหลีกเลี่ยงไฟล์บางไฟล์ที่ไม่ถูกบีบอัด
$bkdir = "E:\BackupsPWS"
$7Zip = 'C:\"Program Files"\7-Zip\7z.exe'
get-childitem -path $bkdir | Sort-Object length |
where
{
    $_.extension -match ".(bak)" -and
    -not (test-path ($_.fullname -replace "(bak)", "7z"))
} |
foreach
{
    $zipfilename = ($_.fullname -replace "bak", "7z")
    Invoke-Expression "$7Zip a $zipfilename $($_.FullName)"
}
get-childitem -path $bkdir |
where {
    $_.extension -match ".(bak)" -and
   (test-path ($_.fullname -replace "(bak)", "7z"))
} |
foreach { del $_.fullname }
ที่นี่คุณสามารถตรวจสอบสคริปต์ PowerShell เพื่อการสำรองข้อมูล, การบีบอัดและการถ่ายโอนไฟล์เหล่านั้นผ่าน FTP
ในกรณีที่คุณติดตั้ง WinRAR:
function ZipUsingRar([String] $directory, [String] $zipFileName)
{
  Write-Output "Performing operation ""Zip File"" on Target ""Item: $directory Destination:"
  Write-Output ($zipFileName + """")
  $pathToWinRar = "c:\Program Files\WinRAR\WinRar.exe";
  [Array]$arguments = "a", "-afzip", "-df", "-ep1", "$zipFileName", "$directory";
  & $pathToWinRar $arguments;
}
ความหมายของอาร์กิวเมนต์: afzip สร้างไฟล์ zip, df ลบไฟล์, ep1 ไม่ได้สร้างพา ธ ไดเร็กทอรีแบบเต็มภายในไฟล์เก็บถาวร
นี่คือตัวอย่างบรรทัดคำสั่งที่สมบูรณ์เพื่อเปิดใช้งานจาก cmd.exe หรือจาก ssh หรือสิ่งที่คุณต้องการ!
powershell.exe -nologo -noprofile -command "&{ Add-Type -A 'System.IO.Compression.FileSystem' [System.IO.Compression.ZipFile]::CreateFromDirectory('c:/path/to/source/folder/', 'c:/path/to/output/file.zip');}"
ความนับถือ
กำลังโหลด [System.IO.IOException]คลาสและการใช้วิธีการเป็นขั้นตอนสำคัญในการระงับข้อผิดพลาดที่ไม่ต้องการเนื่องจากความจริงที่ว่าเป็นคลาสที่ไม่ได้มีอยู่ใน PowerShell ดังนั้นจึงคาดว่าจะเกิดข้อผิดพลาดตามบริบทต่างๆ
ฉันควบคุมข้อผิดพลาดสคริปต์ของฉันกับ T แต่ได้รับเอาต์พุต 'ไฟล์สีแดง' พิเศษจำนวนมากขณะใช้[System.IO.Compression.ZipFile]คลาส
function zipFiles(
    [Parameter(Position=0, Mandatory=$true]
    [string] $sourceFolder,
    [Parameter(Position=1, Mandatory=$true]
    [string]$zipFileName,
    [Parameter(Position=2, Mandatory=$false]
    [bool]$overwrite)
{   
Add-Type -Assembly System.IO
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
$directoryTest = (Test-Path $dailyBackupDestFolder)
$fileTest = (Test-Path $zipFileName)
if ( $directoryTest -eq $false) 
{ 
    New-Item -ItemType Directory -Force -Path $dailyBackupDestFolder 
}
     if ( $fileTest -eq $true)
     {
           if ($overwrite -eq $true ){Remove-Item $zipFileName}
     }   
    try
    {
         [System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder,$zipFileName,$compressionLevel)       
    }
    catch [System.IO.IOException] 
    {
       Write-Output ($dateTime + ' | ' + $_.Exception.Message ) | Out-File $logFile -append -force 
    }
} 
สิ่งที่ฉันทำที่นี่คือการตรวจจับข้อผิดพลาด IO เหล่านี้เช่นการเข้าถึงไฟล์ที่มีอยู่แล้วการจับข้อผิดพลาดนั้นและนำไปยังล็อกไฟล์ที่ฉันดูแลด้วยโปรแกรมขนาดใหญ่
คำสั่งบรรทัดคำสั่งที่สมบูรณ์ใน Windows สำหรับการบีบอัดและคลายไดเรกทอรีมีดังนี้:
สำหรับการบีบอัด:
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('C:\Indus','C:\Indus.zip'); }"สำหรับการแยก:
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem';[IO.Compression.ZipFile]::ExtractToDirectory('C:\Indus.zip','C:\Indus'); }"หินอิออนเข้าใกล้:
https://dotnetzip.codeplex.com/wikipage?title=PS-Examples
รองรับรหัสผ่านวิธีการเข้ารหัสอื่น ๆ ฯลฯ
สคริปต์นี้ทำซ้ำไดเรกทอรีทั้งหมดและบีบอัดแต่ละอัน
รับ ChildItem - คุณสมบัติ d | foreach {write-zip $ .Name "$ ($ .Name) .zip"}