Question:
I’m having trouble getting a .7z
file to extract via Powershell.
My PowerShell function looks like this:
1 2 3 4 5 |
function unzip($file, $destination) { & 'C:\Program Files\7-Zip\7z.exe' x -y $file -o"$destination"; } |
I get this error:
1 2 3 4 5 6 7 8 9 10 11 |
7z.exe : At restoreQA.ps1:26 char:5 + & 'C:\Program Files\7-Zip\7z.exe' x -y $file -o"$destination"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Command Line Error: Too short switch: -o |
There seems to be some sort of parsing error but I’ve tried every different combination to get it working.
Any ideas on why this is not working?
Answer:
You need to put -o in quotes:
1 2 |
& 'C:\Program Files\7-Zip\7z.exe' x -y $file "-o$destination" |