Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

7Zip Powershell not working

I'm having trouble getting a .7z file to extract via Powershell.

My PowerShell function looks like this:

function unzip($file, $destination)
{
    & 'C:\Program Files\7-Zip\7z.exe' x -y $file -o"$destination";
}

I get this error:

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?

like image 371
Jamesking56 Avatar asked Mar 18 '16 13:03

Jamesking56


1 Answers

You need to put -o in quotes:

& 'C:\Program Files\7-Zip\7z.exe' x -y $file "-o$destination"
like image 75
David Martin Avatar answered Oct 16 '22 18:10

David Martin