Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How do I pass an instruction to cmd.exe from a PowerShell command?

Writer 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 below

file.bat simply contains:

iisreset
exit

I 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.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy