Native compression in PowerShell

You can compress files and folders from PowerShell without installing third-party application (required .NET Framework 4.5):

[System.IO.Compression.ZipFile]::CreateFromDirectory(“$Source”, “$Archive”)

Here the function listing to use compression easy:

function Add-Zip ($Source, $Archive){
Compression function

Native compression with latest .NET 4.5 framework

Source file or directory for compression

Archive file name [with path]

————————– EXAMPLE  —————————
Add-Zip -Source C:Temp -Archive

Compress C:temp folder to archive

If (-Not $Source -or -Not $Archive) {
Write-Host ‘One parameter is missing’
} else {
Add-Type -Assembly “System.IO.Compression.FileSystem” ;
[System.IO.Compression.ZipFile]::CreateFromDirectory(“$Source”, “$Archive”) ;


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.