0

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

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

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

The script block is needed, as best I can tell, because this command is being executed in a Windows Server 2008 console, not in powershell.
Script block is not needed, as best as I can tell :), neither for the .ps1 script (as in the example) nor for an executable file. It is the PowerShell that executes the -Command argument.
0

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' ...}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.