Not able to capture output by runas command


I have to automate test cases.


  1. Step:-Open administrative command prompt from powershell.
  2. Step:-Execute a batch file on the administrative command prompt.
  3. Step:-Batch file includes some set of commands, including a execution of an exe.

    For Example:- runas /user:administrator /savecred someCmd.exe >>D:\output.txt

  4. Step:-Capture output of the exe in a variable for verification of the output.

i have used ”
start-process -verb runas cmd.exe $param” cmdlet for opening administrative command prompt(Step 1).
Where $param contains the batch file to be executed.

Problem Statement:- When batch file executes the runas command mentioned above, it opens a new command prompt and the output is displayed in the prompt and it closes itself.
i am not able to capture the output(not getting written in the output.txt) based on which i have to do some verification.


you can use the the output redirection from the batch :


Not able to capture output by runas command by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply