在powershell中使用7z解压缩文件

时间:2017-03-24 11:44:28

标签: powershell 7zip

在PowerShell中使用7z解压缩文件的命令是什么?

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
sz x  $zipfilePath $destinationUnzipPath -aoa -r;

该命令工作正常,但它说没有要处理的文件,一切正常而不是解压缩文件?

4 个答案:

答案 0 :(得分:2)

这最终对我有用sz x -o$destinationUnzipPath $zipfilePath -r ;

答案 1 :(得分:1)

别名不是为了它,它们意味着代理其他命令,而不是命令+参数。

要实现您想要的功能,您需要使用以下功能:

function sz($args) {
    Start-Process "$env:ProgramFiles\7-Zip\7z.exe" -ArgumentList $args
}

答案 2 :(得分:1)

我不想使用别名,函数或Start-Process。在网上浏览了一下之后,我发现了这个宝石(我不记得在哪里):

& ${env:ProgramFiles}\7-Zip\7z.exe x $zipfilePath "-o$($destinationUnzipPath)" -y

如果您不想看到7z的消息,也可以在末尾添加> $null

答案 3 :(得分:0)

使用7zip PowerShell模块,不是很麻烦

#   Install 7zip module

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name 'PSGallery' -SourceLocation "https://www.powershellgallery.com/api/v2" -InstallationPolicy Trusted
Install-Module -Name 7Zip4PowerShell -Force

#   Extract 7zip file

$sourcefile = "c:\source\sample.7z"
Expand-7Zip -ArchiveFileName $sourcefile -TargetPath 'c:\destinaation'
相关问题