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.
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.