Open Administrator Command Prompt from powershell

13,889

one possible way (replace echo test with your commands)

$prog="cmd.exe"
$params=@("/C";"echo test";" >c:\temp\result.txt")
Start-Process -Verb runas $prog $params 
gc c:\temp\result.txt
Share:
13,889
AJ-
Author by

AJ-

Software Engineer

Updated on June 04, 2022

Comments

  • AJ-
    AJ- over 1 year

    i want to do following steps in power shell:- Step 1.) Open Administrative Command prompt from power shell. Step 2.) Execute some command on that administrative command prompt opened in step 1. Step 3.) Capture the output of the command executed in step 2. Step 4.) Close Administrative command prompt opened in step 1.

    after much google and searching i am not able to find the exact power shell command required to achieve the above task. Please tell if the above is possible, if yes then how?