skip to Main Content

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


  1. Chosen as BEST ANSWER

    The solution was that I needed to:

    Import-Module Az.Accounts
    

    before loading my modules, or within my class definition itself.

    class MyClass {
        [string]$azureTenantId
    
        # Constructor
        MyClass () {
    
        }
    
        [void] connectAzAccount(){
            #this is required        
            Import-Module Az.Accounts
            Connect-AzAccount -TenantId $this.azureTenantId
        }
    
        [void] setTenantId([string]$tenantId){
            $this.azureTenantId = $tenantId
        }
    }
    

  2. This error occurs because of a version mismatch between your PowerShell environment and the System.Diagnostics.DiagnosticSource assembly that Connect-AzAccount relies on. You can just update your PowerShell module

    Update-Module -Name Az -Force
    

    Now check again (as you can see this is now updated from 5.1.17763.6292 to 5.1.26100.1882)

    enter image description here

    enter image description here

    and then login using the -DeviceCode parameter to authenticate via device code

    Connect-AzAccount -DeviceCode
    

    enter image description here

    You can always reinstall for a clean slate

    Uninstall-Module -Name Az 
    Install-Module -Name Az
    

    or if possible, try running in PS 7, as it has better compatibility with the Az module.

    References:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search