How to Hide The Yellow Warning Output in PowerShell

Table of Contents

Suppressing warnings in a PowerShell script

In some cases, when you run a PowerShell cmdlet or execute a PowerShell script. You got the yellow warning and the script or command run normally.

You want to suppressing or hiding the yellow warning to make your script look clean.

$subnet = New-AzVirtualNetworkSubnetConfig -Name 'default' -AddressPrefix "172.16.1.0/24"

WARNING: Upcoming breaking changes in the cmdlet 'New-AzVirtualNetworkSubnetConfig' :
Update Property Name
Cmdlet invocation changes :
    Old Way : -ResourceId
    New Way : -NatGatewayId
Update Property Name
Cmdlet invocation changes :
    Old Way : -InputObject
    New Way : -NatGateway
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.
How to Hide The Yellow Warning Output in PowerShell

To achieve that goal, let's add -WarningAction SilentlyContinue parameter into your command in the script.

$subnet = New-AzVirtualNetworkSubnetConfig `
-Name 'default' `
-AddressPrefix "172.16.1.0/24" `
-WarningAction silentlyContinue

If you get the waring when working with the Azure PowerShell module. There’s a native option to disable it.

Get-AzConfig
Key                          Value AppliesTo   Scope
---                          ----- ---------   -----
DefaultSubscriptionForLogin        Az        Default
DisplayBreakingChangeWarning True  Az        Default
DisplaySurveyMessage         True  Az        Default
EnableDataCollection         True  Az        Default

To disable the breaking change warning, you can run the below command:

 Update-AzConfig -DisplayBreakingChangeWarning $false
Key                          Value AppliesTo       Scope
---                          ----- ---------       -----
DefaultSubscriptionForLogin        Az            Default
DisplayBreakingChangeWarning False Az        CurrentUser
DisplaySurveyMessage         True  Az            Default
EnableDataCollection         True  Az            Default

Leave a Comment

Required fields are marked *