7Zip Powershell 不工作

Jam*_*g56 8 windows powershell

我无法.7z通过 Powershell获取要提取的文件。

我的 PowerShell 函数如下所示:

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

我收到此错误:

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
Run Code Online (Sandbox Code Playgroud)

似乎存在某种解析错误,但我尝试了各种不同的组合以使其正常工作。

关于为什么这不起作用的任何想法?

Dav*_*tin 8

您需要将 -o 放在引号中:

& 'C:\Program Files\7-Zip\7z.exe' x -y $file "-o$destination"
Run Code Online (Sandbox Code Playgroud)