PowerShell: Extract Files from Zip Archive

Here’s a quick PowerShell snippet to extract files from a .zip archive:

Add-Type -Assembly System.IO.Compression.FileSystem
$PathToZipFile = "C:\temp\myarchive.zip"
$ExtractPattern = "*.log"
$ExtractDirectory = "C:\temp\extracted"
New-Item -ItemType Directory -Path $ExtractDirectory -Force | Out-Null
$ZipFile = [IO.Compression.ZipFile]::OpenRead($PathToZipFile)
$ZipFile.Entries | 
    Where-Object { $_.Name -like $ExtractPattern } | 
    ForEach {[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$ExtractDirectory\$($_.Name)", $true)}

Hope this helps!

This entry was posted in PowerShell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *