Not able to capture output by runas command.

Welcome Forums General PowerShell Q&A Not able to capture output by runas command.

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 4 months ago.

  • Author
  • #19466

    Points: 0
    Rank: Member

    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.

  • #19467

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    RunAs always starts a new process, and if SomeCmd.exe does not write its output in a way that can be captured, then PowerShell cannot capture it. But in your example, you showed the output being redirected to a D:\output.txt file. In that case, you would read in Output.txt by using Get-Content.

The topic ‘Not able to capture output by runas command.’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort