user3529430 user3529430 - 1 year ago 169
PowerShell Question

How to run cmd as admin and run commands together

I'm looking for a way to be able to open a admin level cmd prompt and then execute a command in that same admin cmd all together in a batch file.

I was trying to fiddle around with:

  • powershell.exe -Command "Start-Process cmd -Verb RunAs"

To do this, but I couldn't figure out a way to send a command to the newly created admin cmd.

What is the best way to achieve this?

Answer Source

You were on the right path, all you needed was the argument -ArgumentList


powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c echo test && pause'"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download