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.
$ErrorActionPreferenceto silence all output. You can also throw it into atry-catchblock. File redirection should work as well2>&1. Best bet is probably atryandcatchblock.