Search code examples
windowspowershell7zip

Extract archive with password that contain double quote


i want to extract an archive called test.rar with 7zip but nothing worked for me Archive: test.rar Password(with quote):"."
I tried

& "C:\Program Files (x86)\7-Zip\7z.exe" t  -p'"".""' test.rar 
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p""."" test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t "-p"."" test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p'"."' test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -'p"."' test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p'"".""' test.rar

Solution

  • Up to at least PowerShell 7.1, passing arguments with embedded " characters to external programs such as 7z.exe is fundamentally broken, unfortunately.

    While there are workarounds, the simpler solution is to provide the password via stdin.

    The post that Mark Tolonen links to shows this technique for cmd.exe, via <, its input-redirection operator, which PowerShell does not support, however.

    Instead, use PowerShell's pipeline to supply data that an external program receives via stdin.

    Assuming that the verbatim password is ".":

    '"."' | & "C:\Program Files (x86)\7-Zip\7z.exe" t test.rar