[PowerShell Tip] – Prevent cmdlet from printing anything to output

Hi,

In this short post, we’ll see how we can prevent a PowerShell cmdlet from printing anything to the std output stream. There are two ways you can do this.

  1. Piping the output of the cmdlet to Out-Null
    e.g. Set-AzureRmContext -SubscriptionId "SubId" | Out-Null
  2. Assigning the output of the cmdlet to $null
    e.g. $null = Set-AzureRmContext -SubscriptionId "SubId"

Either of these would prevent the output being printed to the output stream.

P.S. I learned this today and would love to know if there are more ways to achieve the same 🙂

Hope this helps!

Leave a Reply

Your email address will not be published. Required fields are marked *