Powershell-解压缩7z文件

时间:2020-01-13 13:55:13

标签: powershell

我在使用Powershell解压缩7z文件时遇到了问题,尽管这里有很多需要的信息: unzip file using 7z in powershell

当我使用相同的方法时:

$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"
Set-Alias 7zip $7zipPath
$ZipFilePath = "C:\Users\lpiech\Documents\Lukasz\PowerShell\Test\20200113.7z"
$DestinationUzipPath = "C:\Users\lpiech\Documents\Lukasz\PowerShell\Test\"
7zip x -o$DestinationUzipPath $ZipFilePath -r;

我得到这个答案ResultsScreen 但是在目标位置,“测试”文件夹中没有任何文件,并且脚本未完成,因此它停止了“运行”模式。我应该怎么做才能解压缩文件?

2 个答案:

答案 0 :(得分:0)

现在,借助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:\source\sample.7z"
Expand-7Zip -ArchiveFileName $sourcefile -TargetPath 'c:\destinaation'

答案 1 :(得分:-1)

人们为什么喜欢用艰辛的方式做事?

<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.6.11/core.min.js"></script>