Unzip Password-protected files

时间:2015-08-24 19:13:06

标签: powershell password-protection 7zip

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

1 个答案:

答案 0 :(得分:4)

尝试这种方式:

$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