2011-06-28 39 views
0

我想在控制檯中使用powershell執行腳本塊,並且我無法完全像我想要的那樣獲得語法工作。我需要另一雙眼睛,因爲我一直在盯着這個很長一段時間。有人能指出我做錯了什麼嗎?PowerShell腳本塊語法給我帶來麻煩

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

嘗試此作爲命令(I不能對此進行測試):(無需腳本塊,實際上)

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

+0

盡我所知,腳本塊是必需的,因爲此命令在Windows Server 2008控制檯中執行,而不是在PowerShell中執行。 –

+0

不需要腳本塊,就像我可以告訴的那樣:),既不是.ps1腳本(如示例中),也不是可執行文件。它是執行-Command參數的PowerShell。 –

+0

是的,很對。我過度格式化。 –

0

我想想我可能已經想通了:在腳本塊內部,我還需要包含第二個調用操作符,如下所示:

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