Monday, September 19, 2022

Hiding Outputs of PowerShell

There might be situations where you want to hide outputs from PowerShell scripts. This blog explains how to achieve that.

Following code sample is used to connect with azure portal and show the resource group details. To avoid output values visible in the logs, we can add | Out-Null as shown in the following sample. You can learn more about Out-Null from here.

.{

az login --service-principal -u <<your_client_id>> -p <<spn secret>> -t <<tenant_id>> -o table

    az group show --name <<resource group name>> | ConvertFrom-Json

    }|Out-Null

    

Without Out-Null, logs will be looking similar to below.


With Out-Null, logs will be looking similar to below.



No comments:

Post a Comment