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 |
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
Another one I haven't tested: