Using the CreateFromDirectory and ExtractToDirectory methods, it is possible to compress and extract files. In this tip I will show different constructors that can be used to either compress or extract files using this class. The following example will compress the files stored in the c:\testing folder:
Add-Type -Assembly 'System.IO.Compression.FileSystem' [System.IO.Compression.ZipFile]::CreateFromDirectory('c:\testing', 'c:\testing.zip','Optimal',$false)
When you want to extract files, use the ExtractToDirectory method:
In PowerShell 5.0 the Compress-Archive and Expand-Archive cmdlets are available to simplify working with compressed archives.
For more information about the ZipFile class and the Compress-Archive and Expand-Archive cmdlets please refer to the following articles: