【问题标题】:A positional parameter cannot be found that accepts argument 'Files\'找不到接受参数“文件\”的位置参数
【发布时间】:2019-10-04 22:58:19
【问题描述】:

如果我将目标路径作为 C:\但是,如果我指定 C:\Users\test\Downloads 它可以工作。

PS C:\Users\test\Downloads> Expand-Archive -Path C:\Windows\Temp\nginx-1.16.1.zip -DestinationPath  C:\Program Files\

Error:
    Expand-Archive : A positional parameter cannot be found that accepts argument 'Files\'.
    At line:1 char:1
    + Expand-Archive -Path C:\Windows\Temp\nginx-1.16.1.zip -DestinationPat ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Expand-Archive], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Expand-Archive

我尝试传递 '$env:PROGRAMFILES' 并得到同样的错误。

Expand-Archive -Path C:\Windows\Temp\nginx-1.16.1.zip -DestinationPath '$env:PROGRAMFILES' 

如何将参数 C:\Program Files\ 作为目标路径传递给 powershell。

【问题讨论】:

  • 你可以试试"C:\Program Files\"
  • 你需要在最终路径周围加上引号......嵌入的空间让 PoSh 认为你有一个新项目。 [咧嘴]
  • 愚蠢的错误。它的工作。谢谢!
  • Re '$env:PROGRAMFILES'单引号字符串从不插入(扩展嵌入变量引用),只有双引号字符串可以;但是,在这种情况下,您根本不需要引用:$env:ProgramFiles 可以(使用 变量引用,其值中的空格在 PowerShell 中不是问题)。我也鼓励你接受马修的回答。

标签: powershell


【解决方案1】:

您遇到的问题是您使用的 C:\Program Files\ 包含一个空格,因此您需要包装为 "C:\Program Files\" 以便 PowerShell 完成。

【讨论】:

    猜你喜欢
    • 2016-07-06
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 2019-12-23
    • 1970-01-01
    相关资源
    最近更新 更多