Question:
I have to automate test cases.
Tasks:-
- Step:-Open administrative command prompt from powershell.
- Step:-Execute a batch file on the administrative command prompt.
- 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
- 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.
Answer:
you can use the the output redirection from the batch :
1 2 3 4 |
$params="/C ipconfig /all 2>&1 >>c:\temp\test.txt" start-process -verb runas cmd.exe $params gc c:\temp\test.txt |