使用PowerShell压缩和解压ZIP包

更新记录
本文迁移自Panda666原博客,原发布时间:2021年7月13日。

解压ZIP包

使用PowerShell的Expand-Archive命令。PowerShell官方文档地址。
命令格式:

Expand-Archive -Path  -DestinationPath  -Confirm 

解压压缩包

Expand-Archive -Path .\panda.Zip -DestinationPath F:\dd -Confirm 

压缩ZIP包

使用PowerShell的Compress-Archive命令。PowerShell官方文档地址。
命令格式:

Compress-Archive -Path  -DestinationPath  -Confirm 

实例:压缩多个文件

$compress = @{   Path = C:\Reference\Draftdoc.docx, C:\Reference\Images\*.vsd   CompressionLevel = Fastest   DestinationPath = C:\Archives\Draft.Zip }  Compress-Archive @compress 

实例:压缩文件

Compress-Archive -Path ‪E:\test.txt -DestinationPath F:\panda.zip -Confirm 

实例:压缩目录

Compress-Archive -Path E:\新建文件夹\ -DestinationPath F:\panda.zip -Confirm 

实例:压缩目录(不包含根目录)

Compress-Archive -Path E:\新建文件夹\* -DestinationPath F:\pan.zip -Confirm 

实例:压缩目录(只包含根目录的文件)

Compress-Archive -Path E:\文件夹\*.* -DestinationPath F:\pan.zip -Confirm