Everything that I have found with a similar error seems to be for developers working in their C# / Visual Studio environment. I’m just trying to connect to Azure with Powershell. This seems to be a problem only with Powershell versions that are newer than 5.1.17763.5576. I have other VM’s where things work fine and are practically identical, but the Powershell version is 5.1.17763.5576 or older. So, to state it plainly, my credentials are not the problem, and updating PowerShell to the latest is not the solution.
PS C:Windowssystem32> $psversiontable
Name Value
---- -----
PSVersion 5.1.17763.6292
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.6292
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:Windowssystem32> connect-azaccount
Please select the account you want to login with.
WARNING: Unable to acquire token for tenant 'organizations' with error 'InteractiveBrowserCredential authentication
failed: Could not load type 'System.Diagnostics.Metrics.Meter' from assembly 'System.Diagnostics.DiagnosticSource,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.'
WARNING: Please run 'Connect-AzAccount -DeviceCode' if browser is not supported in this session.
connect-azaccount : InteractiveBrowserCredential authentication failed: Could not load type
'System.Diagnostics.Metrics.Meter' from assembly 'System.Diagnostics.DiagnosticSource, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
At line:1 char:1
+ connect-azaccount
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Connect-AzAccount], AuthenticationFailedException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
How do I fix this?
Things I’ve tried that do not work:
Update-Module -Name Az -Force (does not fix this)
Uninstall/Reinstall Module (does not fix this)
After playing with this more, I found that the problem is specifically AFTER I load my .psm1 PS module and instantiate it: ( It only happens after I [MyClass]::new() )
2
Answers
The solution was that I needed to:
before loading my modules, or within my class definition itself.
This error occurs because of a version mismatch between your PowerShell environment and the
System.Diagnostics.DiagnosticSource
assembly thatConnect-AzAccount
relies on. You can just update your PowerShell moduleNow check again (as you can see this is now updated from 5.1.17763.6292 to 5.1.26100.1882)
and then login using the
-DeviceCode
parameter to authenticate via device codeYou can always reinstall for a clean slate
or if possible, try running in PS 7, as it has better compatibility with the Az module.
References: