Not able to capture output by runas command.

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 2 years, 2 months ago.

  • Author
    Posts
  • #19466
    Profile photo of Ankit Jh
    Ankit Jh
    Participant

    I have to automate test cases.

    Tasks:-

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.