skip to Main Content

I meant to run a long Powershell script on Azure CLI which will produce some outputs. My requirement is that I need those outputs on terminals as well as in a file, Is this achievable?

In Azure Shell, the history of terminal output is not great. You can not scroll up to the point you started.

I need to have a proof of the output.
Please suggest.

2

Answers


  1. Yes, it is possible to capture the output of a PowerShell script both in the terminal and a file when using Azure CLI.

    To achieve this, you can utilize the redirection operator (>) in PowerShell, which allows you to redirect the output to a file while still displaying it in the terminal. Below is an example that demonstrates how you can accomplish this:

    # Run your PowerShell script and redirect the output to a file
    .your_script.ps1 > output.txt
    
    

    In the above command, replace your_script.ps1 with the actual name of your PowerShell script, and output.txt with the desired filename for the output file.

    By using the > operator, the standard output of your script will be redirected to the specified file, while still being displayed in the terminal as the script executes.

    Once the script finishes running, you can access the output.txt file to view the captured output. This approach allows you to have the output available in both the terminal and the file, providing you with the necessary proof while retaining the ability to scroll through the terminal history.

    Login or Signup to reply.
  2. This includes both regular and error output. You can redirect this to a file using the *> operator:

    .YourScript.ps1 *> alloutput.txt
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search