简体   繁体   中英

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?

你需要把-o放在引号中:

& 'C:\Program Files\7-Zip\7z.exe' x -y $file "-o$destination"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM