Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

How can I run a CMD command with parameters from within a Powershell script?

Hello Powershell Experts,

I have an executable that installs an agent onto my PC.   I want to run this executable from within a Powershell script.  If I run the following commands from a CMD prompt, the agent installs as expected:
C:\>cd agentfolder
C:\AgentFolder>Agent-x64.exe /v" /qn /norestart  AGCONTEXT=111222333aaabbb"

I thought I would be able to do something like the following within my script:
& “C:\AgentFolder\ Agent-x64.exe /v" /qn /norestart  AGCONTEXT=111222333aaabbb"

That did not work.  I also tried:
Start-process –filepath “C:\AgentFolder\ Agent-x64.exe /v" /qn /norestart  AGCONTEXT=111222333aaabbb"

This didn’t work either.  How can I run the command with the needed parameters from within a powershell script?

As always, thanks in advanced for your help.

Nick
Avatar of oBdA
oBdA

That should work just fine, but you have a space right in front of "Agent-x64.exe", and you didn't close the program path with a double quote:
Try it like this:
& "C:\AgentFolder\Agent-x64.exe" /v" /qn /norestart  AGCONTEXT=111222333aaabbb"

Open in new window

invoke-command -scriptblock {“C:\AgentFolder\ Agent-x64.exe /v" /qn /norestart  AGCONTEXT=111222333aaabbb"}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ndalmolin_13

ASKER

Thanks for the explanations.