Powershell可通用的ZIP解压方法


先前的方法都受版本限制,下面介绍一种WindowsShell方法来实现解压缩:

$Source = 'C:\somezipfile.zip'
$Destination = 'C:\somefolder'
$ShowDestinationFolder = $true

if ((Test-Path $Destination) -eq $false) 
{
  $null = mkdir $Destination 
}

$shell = New-Object -ComObject Shell.Application
$sourceFolder = $shell.NameSpace($Source)
$destinationFolder = $shell.NameSpace($Destination)
$DestinationFolder.CopyHere($sourceFolder.Items())

if ($ShowDestinationFolder) 
{
  explorer.exe $Destination
}

随意修改文件扩展名可能会失败,这个方法的优势就是使用系统自身的shell方法就可以解决问题,它同样也支持CAB文件。
原文地址:Unzipping ZIP Files with any PowerShell Version

本文链接: https://www.pstips.net/unzipping-zip-files-with-any-powershell-version.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注