PowerShell – Create Zip File

|

Scenario, you’re on a Windows Server and don’t want to or can’t install a zip program.

This script will help you create a zip file without any special program.

Caveat: Currently this does not give you any kind of status so it could seem to be doing nothing for a while depending on the size of the directory you want/need to compress.

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)
}

ZipFiles c:\Drivers.zip D:\
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.