ccoutinho
ccoutinho

Reputation: 4556

How can I supress a specific warning in a PowerShell script?

I am working on a PowerShell script that very often produces the same, irrelevant warnings. This warning pollutes the script output, and I want to get rid of it. However, I don't think it is a good practice to omit all warning, so I was wondering if it would be possible to omit very specific warnings?

In my case, I want to remove the following warnings:

WARNING: TenantId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' contains more than one active subscription. First one will be selected for further use. To select another subscription, use Set-AzContext.

WARNING: Unable to acquire token for tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with error 'You must use multi-factor authentication to access tenant xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, please rerun 'Connect-AzAccount' with additional parameter '-TenantId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.'

Any idea how can this be achieved?

Upvotes: 0

Views: 927

Answers (1)

Damien Caro
Damien Caro

Reputation: 70

First I'd recommend that you use the most recent version of Az.Accounts to ensure that you are not facing any knowns issues (currently version 2.5.2). When running Connect-AzAccount we populate the local context based on the first 25 subscriptions returned. It seems that one of those requires MFA therefore cannot get a token. To avoid the warning, try to be specific of the subscription/tenant that you want to use.

Upvotes: 0

Related Questions