Created
February 1, 2017 09:34
-
-
Save alst74/499a101f89d92d99c48cdd6f3e507254 to your computer and use it in GitHub Desktop.
Powershell v3 unzip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Expand-ZIPFile($file, $destination) { | |
$shell = new-object -com shell.application | |
$zip = $shell.NameSpace($file) | |
foreach($item in $zip.items()) | |
{ | |
$shell.Namespace($destination).copyhere($item) | |
} | |
} | |
Expand-ZIPFile –File testfile.zip –Destination c:\temp |
Another one I haven't tested:
$sourceFile = 'C:\assets\Microsoft.Azure.ServiceFabric.WindowsServer.5.3.204.9494.zip'
$targetFolder = 'C:\Microsoft.Azure.ServiceFabric.WindowsServer'
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
[System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile, $targetFolder)
Powershell v5 -
Get-Command *archive | ft CommandTYpe, Name -a
CommandType Name
———– —-
Function Compress-Archive
Function Expand-Archive
To compress
$files = Get-ChildItem -Path C:\Scripts -Filter *.csv | select -ExpandProperty Fullname
Compress-Archive -Path $files -DestinationPath C:\Scripts\t1.zip -CompressionLevel Optimal
or a single file
Compress-Archive -Path c:\scripts\test.csv -DestinationPath C:\Scripts\t2.zip -CompressionLevel Optimal
To uncompress
Expand-Archive -Path C:\Scripts\t1.zip -DestinationPath c:\scripts
if you need to overwrite files:
Expand-Archive -Path C:\Scripts\t1.zip -DestinationPath c:\scripts -Force
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unzip files in Powershell v3
Simple function to unzip files in powershell version 3.
Similar can be found here:
https://www.howtogeek.com/tips/how-to-extract-zip-files-using-powershell/