I am trying to run a cmd file through powershell. The file is located in a folder inside Program Files.
I have tried
invoke-item -path "c:\program files\myProgram\myfile.cmd" which gave me cmd file not found message.
Then, I tried to put that in variable and pipe it to cmd
$myvariable = "c:\program files\myProgram\myfile.cmd"
$myvariable | cmd
That gave an error "'C:\Program' is not recognized as an internal or external command". Apparently, the space in the string there is a problem.
Next, I tried to cd to "c:\program files\myProgram" and then run cmd /c myfile.cmd. Now that seems to work except the powershell does not stop and has to be manually stopped.
Any suggestions as to how to run that cmd from within powershell script? When run from command prompt (elevated privilege) it works fine.