-1

I've got a problem with unzipping 7z file with Powershell although much needed information is here: unzip file using 7z in powershell

When i use same approach:

$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;

i get this answer ResultsScreen but in destination i don't have any files in "Test" folder and script isn't finished it stops i "Running" mode. What should i do to get unzipped files?

Community
  • 1
  • 1
LukasP
  • 1
  • 1
  • Ok, i have answer. Maybe someone could use it. I've changes last line of code like this: '7zip x -o"$DestinationUzipPath" $ZipFilePath -r;' – LukasP Jan 13 '20 at 13:58

2 Answers2

0

Why do people like doing it the hard way?

$env:path += ';C:\Program Files\7-Zip'
7zip x -oDocuments\Lukasz\PowerShell\Test Documents\Lukasz\PowerShell\Test\20200113.7z -r 
js2010
  • 23,033
  • 6
  • 64
  • 66
0

Now, with PowerShell 7zip module, it is hassle free

#   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'
Prosenjit Sen
  • 326
  • 4
  • 7