Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
Created August 22, 2018 04:46
Show Gist options
  • Save GeoffWilliams/8c3d463867d8234b0e2b979c6bd626df to your computer and use it in GitHub Desktop.
Save GeoffWilliams/8c3d463867d8234b0e2b979c6bd626df to your computer and use it in GitHub Desktop.
Unzip a file using powershell, overwriting any existing files
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zipFile = [System.IO.Compression.ZipFile]::openread("c:\Vagrant\download_and_do\spec\mock\test.zip")
foreach ($zipFileEntry in $zipFile.Entries) {
$pwd = (Get-Item -Path ".\" -Verbose).FullName
$outputFile = [io.path]::combine($pwd, $zipFileEntry.FullName)
$dir = ([io.fileinfo]$outputFile).DirectoryName
if (-not(Test-Path -type Container -path $dir)) {
mkdir $dir
}
if ($zipFileEntry.Name -ne "") {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipFileEntry, $outputFile, $true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment