PowerShell for Windows Admins

Oct 25 2014   3:13AM GMT

PowerShell 5 – zip and unzip

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


One the extras in PowerShell 5.0 is a couple of cmdlets for working 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

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: