Windows PowerShell脚本块语法给我带来了麻烦
我正试图在控制台中使用powershell执行脚本块,但我不能完全按照我想要的方式使用语法。我需要另一双眼睛,因为我已经盯着这个看了很长时间了。有人能指出我做错了什么吗Windows PowerShell脚本块语法给我带来了麻烦,windows,powershell,console,Windows,Powershell,Console,我正试图在控制台中使用powershell执行脚本块,但我不能完全按照我想要的方式使用语法。我需要另一双眼睛,因为我已经盯着这个看了很长时间了。有人能指出我做错了什么吗 C:\Users\Administrator.MAUL>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -Inputformat None -ExecutionPolicy Unrestricted -Command
C:\Users\Administrator.MAUL>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -Inputformat None -ExecutionPolicy Unrestricted -Command "& {'C:\Users\Administrator.MAUL\Scripts\InstallTransportAgent.ps1' -ExchangeDir 'C:\Program Files\Microsoft\Exchange Server\V14' -AgentDir 'C:\Users\Administrator.MAUL\Project\TransportAgent\bin\x64\Debug' }"
结果是:
You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:126
+ & {'C:\Users\Administrator.MAUL\InstallTransportAgent.ps1' - <<<< ExchangeDir 'C:\Program Files\Microsoft\Exchange Server\V14' -AgentDir 'C:\Users\Administrator.MAUL\Project\TransportAgent\bin\x64\Debug' }
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : ExpectedValueExpression
必须在“-”运算符的右侧提供值表达式。
第1行字符:126
+&{C:\Users\Administrator.MAUL\InstallTransportAgent.ps1'-尝试将此作为命令(我无法测试此命令):
(实际上不需要脚本块)我想我可能已经找到了答案:在脚本块中,我还需要包含第二个呼叫操作符,如下所示:
... -Command "& {&'path/to/exe' ...}"
据我所知,需要脚本块,因为此命令是在Windows Server 2008控制台中执行的,而不是在powershell中执行的。据我所知,不需要脚本块:),对于.ps1脚本(如示例中所示)或可执行文件都不需要脚本块。执行-command参数的是powershell。
... -Command "& {&'path/to/exe' ...}"