【发布时间】:2020-10-08 15:38:20
【问题描述】:
我无法通过传递两个参数(路径)使这个 cmd 命令运行 powershell 脚本。
C:\WINDOWS\System32>powershell -command \"C:\Apps\Scripts\Test\testing.ps1" \"\\Data1\dataholder$\office\J Smith\backup\" \"\\Data1\dataholder$\office\J Smith\backup2\"
我收到以下错误:
At line:1 char:36
+ ... ps\Scripts\Test\testing.ps1 "\\Data1\dataholder$\office\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '\\Data1\dataholder$\office' in expression or statement.
At line:1 char:146
+ ... Smith\backup" "\\Data1\dataholder$\office\J Smith\backup2"
+ ~
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
知道为什么会失败吗?
我不得不修改通向脚本的路径。现在命令看起来像这样:
C:\WINDOWS\System32>powershell -command \"C:\Apps\Scripts\Power test\testing.ps1" \"\\Data1\dataholder$\office\J Smith\backup\" \"\\Data1\dataholder$\office\J Smith\backup2\"
由于脚本路径中的空间而导致失败,知道如何处理吗?
【问题讨论】:
-
你的第一个引号转义是不必要的
\"C:\Apps\Scripts\Test\testing.ps1"-->"C:\Apps\Scripts\Test\testing.ps1"
标签: powershell cmd path parameter-passing