在powershell中使用7z解压文件

Dee*_*lra 9 powershell 7zip

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

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
sz x  $zipfilePath $destinationUnzipPath -aoa -r;
Run Code Online (Sandbox Code Playgroud)

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

Dee*_*lra 9

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


Joã*_*cca 9

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

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

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


Pro*_*Sen 8

有了 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'
Run Code Online (Sandbox Code Playgroud)