Powershell - 解压缩 7z 文件



我在使用 Powershell 解压缩 7z 文件时遇到了问题,尽管这里提供了急需的信息: 在PowerShell中使用7z解压缩文件

当我使用相同的方法时:

$7zipPath = "$env:ProgramFiles7-Zip7z.exe"
Set-Alias 7zip $7zipPath
$ZipFilePath = "C:UserslpiechDocumentsLukaszPowerShellTest20200113.7z"
$DestinationUzipPath = "C:UserslpiechDocumentsLukaszPowerShellTest"
7zip x -o$DestinationUzipPath $ZipFilePath -r;

我得到这个答案 结果屏幕 但是在目标中,我的"测试"文件夹中没有任何文件,并且脚本未完成,它停止了"运行"模式。我应该怎么做才能获得解压缩的文件?

为什么人们喜欢用艰难的方式做这件事?

$env:path += ';C:Program Files7-Zip'
7zip x -oDocumentsLukaszPowerShellTest DocumentsLukaszPowerShellTest20200113.7z -r 

现在,有了PowerShell 7zip模块,它就无忧无虑

了。
#   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:sourcesample.7z"
Expand-7Zip -ArchiveFileName $sourcefile -TargetPath 'c:destinaation'

最新更新