header image

PowerShell 5 – zip and unzip

Posted by: | October 25, 2014 Comments Off on PowerShell 5 – zip and unzip |

One the extras in PowerShell 5.0 is a couple of cmdlets for workign with zip archives. Actually, you’ll find they are PowerShell advanced functions if you look in the module which you’ll find at C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive

 

You get 2 cmdlets:

£> 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

under: PowerShell v5

Comments are closed.

Categories