powershell zip code example

Example 1: powershell zip multiple files

Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip

Example 2: powershell zip multiple files

$compress = @{
  Path = "C:\Reference\Draftdoc.docx", "C:\Reference\Images\*.vsd"
  CompressionLevel = "Fastest"
  DestinationPath = "C:\Archives\Draft.Zip"
}
Compress-Archive @compress

Example 3: Compress files powershell

Compress-Archive -Path (Join-Path $filesDir "*.*") -DestinationPath (Join-Path $outDir "Files_Compressed.zip")

Example 4: Compress files powershell

#Ordner komprimieren
Compress-Archive

#Ordner dekomprimieren
Expand-Archive

Example 5: browse for zip file powershell

function BrowseForFile($initialFile="")
{   
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |  Out-Null
    $openFileDialog                    = New-Object System.Windows.Forms.OpenFileDialog
    $openFileDialog.Title              = "Choose a ZIP file"
    $openFileDialog.initialDirectory   = $PSScriptRoot
    $openFileDialog.filter             = "zip folder (*.zip)| *.zip"

    if ($openFileDialog.ShowDialog() -eq "OK")
    {
       return $openFileDialog.FileName
    } else {
       return $initialFile
    }
}



$window.FindName("ZipFile").Text = $PSScriptRoot + "\_SampleFiles\Content.zip"

# Browse for zip file
$BrowseForZIPFileButton = $window.FindName("BrowseForZIPFile")
$BrowseForZIPFileButton.Add_Click({
   $currentFile = $window.FindName("ZipFile").Text
   $window.FindName("ZipFile").Text = BrowseForFile($currentFile)
})

Tags:

Misc Example