Unzip Password-protected files

Harry Singh picture Harry Singh · Aug 24, 2015 · Viewed 9.9k times · Source

I am trying to extract files from a password-protected zip, in a USB drive, using PowerShell. I have looked up many ways but the easiest one doesn't seem to work.

$7ZipPath = "C:\Program Files\7-Zip\7z.exe"
$zipFile = "E:\passwordprotectedtest.zip"
$zipFilePassword = "Foo"

& $7ZipPath e -oE:\ -y -tzip -p "$zipFilePassword" "$zipFile"

I keep getting this error:

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Error
Cannot use absolute pathnames for this command

I then moved to the file to my desktop, changed $zipFile = "passwordprotectedtest.zip", changed -oE:\ to -oC:\.

That fixed the pathname error but started getting this error instead

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Error
Cannot find archive

Answer

Dmitry VS picture Dmitry VS · Sep 2, 2015

Try this way:

$7ZipPath = '"C:\Program Files\7-Zip\7z.exe"'
$zipFile = '"e:\passwordprotectedtest.zip"'
$zipFilePassword = "Foo"
$command = "& $7ZipPath e -oe:\ -y -tzip -p$zipFilePassword $zipFile"
iex $command