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