A simple zip function in Powershell

2016-04-05

Code

1 minute

function ZipFiles($ZipFileName, $SourceDir)
{
    Add-Type -Assembly System.IO.Compression.FileSystem
    $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
    [System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDir, $ZipFileName, $compressionLevel, $false)
}

To use the function:

ZipFiles -ZipFileName test.zip -SourceDir .\folder\to\zip