Powershell warning when running script

Kelly Garcia
Kelly Garcia used Ask the Experts™

When I run my powershell script and getting those warning, how do i stop them from appearing?

WARNING: 16:10:30 - *** The namespace for all the model classes will change from
Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.
WARNING: 16:10:30 - *** The namespace for output classes will be uniform for all classes in future releases to make it
independent of modifications in the model classes.
WARNING: 16:10:30 - The arguments Categories and Timegrains now have aliases Category and Timegrain respectively. The
plural names will be removed in future releases.

Open in new window

Thank you for your help.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Michael B. SmithManaging Consultant

The "warning stream" is number 3.  So re-direct that output to $null.

For example:

write-warning "this is warning text" 3>$null

Open in new window

If you are working with a pipeline, that redirection goes BEFORE the pipe symbol, immediately to the right of the cmdlet generating the warning.
Most Valuable Expert 2018
Distinguished Expert 2018
That's probably from importing the Azure module; just add -WarningAction SilentlyContinue as Import-Module argument.
Works for any cmdlet that writes stuff to the Warning stream.
To suppress warnings for the rest of the script, you can set the $WarningPreference variable to SilentlyContinue.
Or use something like this if you don't want to add the -WarningAction ... all over the place:
$WarningPreference = SilentlyContinue
# Commands with known warnings you want to suppress ...
$WarningPreference = Continue

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial