0

I am executing a PS script to display few things from Azure. But, for some cmdlets the warnings gets written to the output.

like this:

WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell i n an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care th at none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide.

I have used the -ErrorAction SilentlyContinue which will prevent the errors from printing. But is there a way to avoid warnings in the output while executing the command.

P.S: I am well aware of how to get rid of the above warning. Just curious if there is any way we can keep the warnings from displaying.

2
  • $ErrorActionPreference to silence all output. You can also throw it into a try-catch block. File redirection should work as well 2>&1. Best bet is probably a try and catch block. Commented Feb 19, 2021 at 13:42
  • @AbrahamZinala Just now tried with the try and catch. It still writes the warnings. Commented Feb 19, 2021 at 13:48

1 Answer 1

3

You're trying to use -ErrorAction on a Warning, which is not an Error.

To silence Warnings, you need to use -WarningAction SilentlyContinue

Sign up to request clarification or add additional context in comments.

1 Comment

$ErrorActionPreference = "SilentlyContinue" $WarningPreference = "SilentlyContinue". I have done this. It's working as expected now. Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.