Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active December 31, 2015 22:29
Show Gist options
  • Save grenade/8054334 to your computer and use it in GitHub Desktop.
Save grenade/8054334 to your computer and use it in GitHub Desktop.
Extract a single file from a zip file
param(
[string] $archive,
[string] $savePath,
[string] $filename = [System.IO.Path]::GetFileName($savePath)
)
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
$outStream = New-Object System.IO.FileStream ("$savePath"), 'Create'
$inStream = ([System.IO.Compression.ZipFile]::OpenRead($archive).Entries | Where { $_.Name -eq $filename }).Open()
$inStream.CopyTo($outStream)
$inStream.Close()
$outStream.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment