[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!

Advertisements

Your comments or opinions.....

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s