How do I pass an instruction to cmd.exe from a PowerShell command?
Olivia Zamora
I have a batch file which runs a command (that is in another batch file) in administrative mode via:
//instructions above
powershell.exe -Command "Start-Process file.bat -Verb RunAs"
//instructions belowfile.bat simply contains:
iisreset
exitI want to be able to run this directly in a single batch file. Can this be done? I was hoping for somthing like:
powershell.exe -Command "Start-Process 'iisReset && exit' -Verb RunAs" But this does not work.
1 Answer
The Start-Process cmdlet assumes that the first parameter (-FilePath, specifically) is only the filename of the program to run. That's why you were getting "cannot find the file specified" errors. The -ArgumentList option is designed to pass parameters. Therefore, this should do what you want:
powershell -Command "Start-Process 'cmd' -Verb RunAs -ArgumentList '/c calc && exit'"Note that you might not even need the && exit part in some circumstances.