PowerShell: .NET 4.0 zip file handling

The .NET Framework 4.0 brought an upgrade to the System.IO.Compression classes allowing native handling of zip files. The two scripts below demonstrate compression and expansion uses these classes.

The relevant assemblies must be loaded if they are to be used.

Add-Type -Assembly 'System.IO.Compression'
Add-Type -Assembly 'System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Once that’s done, the following functions may be used.

Compress-Item

Expand-Item

PowerShell: .NET 4.0 zip file handling
Share this