开发者

PowerShell scriptblock syntax is giving me trouble

I'm trying to execute a script block using powershell in the console, and I can't quite get the syntax working like I want. I need another set of eyes, because I've been staring at this for a long time. Can someone point out what I'm doing wrong?

C:\Users\Administrator.MAUL>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -Inputforma开发者_JAVA技巧t 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' }"

The result:

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


Try this as the command (I cannot test this):

"& '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'"

(script block is not needed, actually)


I think I may have figured it out: inside the script block, I need to also include a second call operator, like this:

... -Command "& {&'path/to/exe' ...}"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜