【发布时间】: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