Closed TrondHaugmo closed 1 year ago
On request from the support technician which is working on the support case we have also reported an issue for here (that too on request by the support technician), we have tried to authenticate and run the Connect-MgGraph
cmdlet in the context of a different admin account on the system in question. The other admin account attempted has also the ability to PIM-elevate to gain Azure AD "Global Administrator" role access. This has led to the following additional findings that may be of relevance:
Connect-MgGraph
(while having the admin-account elevated to "User Administrator" and "Global Reader") was performed (both with and without specifiying the -Scopes
parameter). When the -Scopes
parameter was used, we defined it with this value: "User.Read.All", "Group.ReadWrite.All"
TypeInitializationException
error/exception) got displayedConnect-MgGraph
was performed, but this time while the admin account had the "Global Administrator" role elevated (activated) for the account.
Connect-MgGraph
command seemed to complete successfully), and it was also afterwards possible to successfully run a command like Get-MgBetaUser -UserID [id]
to retrieve information about a user through the Microsoft.Graph API interface.Connect-MgGraph -Scopes "Users.Read.All"
(while having only "Global Reader" role activated) was also attempted, but that also resulted in the now quite familiar TypeInitializationException
error.I am having the exact same issue, running our script with Powershell 7 works fine, but we cannot introduce Powershell 7 where the script needs to be run.
On the same system, Connect-AzAccount fails as well with Windows Powershell 5.1, this could be related to the root cause of the issue:
Connect-AzAccount : Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identit
y.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.
At C:\REDACTED.ps1:366 char:1
+ Connect-AzAccount | Out-Null
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Connect-AzAccount], MissingMethodException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2148 this issue could be related
With the comment from @fujiant about issues also with Connect-AzAccount
on his system I checked that on my side. It has always worked in the past, but I thought it could have broken with the install of the Microsoft.Graph modules, so worth checking. However, it seems like Connect-AzAccount
(and other [verb]-AzAD[res_type]
cmdlets) still work on my system where we have the "TypeInitializationException*" issue (when running Connect-MgGraph
) independently of if I try to run Connect-AzAccount
or Connect-MgGraph
first or last.
However, the version of Az.Accounts on my system is a bit dated (while Microsoft.Graph.Authentication is fully up-to-date) as you can see below:
PS C:\Windows\system32> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.7.2 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Script 5.3.1 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}
Script 1.0.0.0 ISE {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}
Script 2.4.0 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext...}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
PS C:\Windows\system32>
I tried to downgrade Microsoft.Graph.Authentication version to 1.28.0 and it worked briefly. The only reliable workaround I found was not to call Connect-AzAccount and Connect-MgGraph in the same Powershell script, eg. not including the Az module and Graph module in the same file.
@TrondHaugmo could you please share the output of this command [System.AppDomain]::CurrentDomain.GetAssemblies() | select FullName, Location
Hello @timayabi2020, here is the requested output from running [System.AppDomain]::CurrentDomain.GetAssemblies() | select FullName, Location
on my system:
Note: I did output the result to a file while setting
$PSDefaultParameterValues['out-file:width'] = 2000
to ensure the full filepath was shown forLocation
in the output (not sure if it matters, but assumed that was relevant).
FullName Location
-------- --------
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
powershell_ise, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
Microsoft.PowerShell.ISECommon, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.ISECommon\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.ISECommon.dll
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll
System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll
System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll
System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll
System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll
System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll
Microsoft.PowerShell.GPowerShell, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.GPowerShell\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.GPowerShell.dll
System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.Composition\v4.0_4.0.0.0__b77a5c561934e089\System.ComponentModel.Composition.dll
Microsoft.PowerShell.Editor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Editor\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Editor.dll
WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll
PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll
PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_64\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll
System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll
System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll
UIAutomationProvider, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationProvider\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationProvider.dll
Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll
MetadataViewProxies_ea0543bb-39aa-4d47-8881-1606d0ad9972, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Management.dll
System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.DirectoryServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.dll
Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Management.Infrastructure\v4.0_1.0.0.0__31bf3856ad364e35\Microsoft.Management.Infrastructure.dll
PresentationFramework.Aero2, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll
PresentationFramework-SystemXml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll
System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Microsoft.PowerShell.Security, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Security\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Security.dll
System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_64\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll
System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll
Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll
Microsoft.PowerShell.GraphicalHost, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.GraphicalHost\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.GraphicalHost.dll
UIAutomationTypes, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll
Microsoft.GeneratedCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
PresentationFramework-SystemData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemData\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemData.dll
PresentationFramework-SystemCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemCore\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemCore.dll
Windows.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.UI.winmd
Windows.Foundation, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.Foundation.winmd
System.Runtime.InteropServices.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.InteropServices.WindowsRuntime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.InteropServices.WindowsRuntime.dll
System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.WindowsRuntime\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.WindowsRuntime.dll
Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.dll
System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration.Install\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.Install.dll
Microsoft.Azure.PowerShell.Authentication.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Authentication.Abstractions.dll
Microsoft.Azure.PowerShell.Authentication, Version=2.7.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Authentication.dll
Microsoft.Azure.PowerShell.Authenticators, Version=2.7.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Authenticators.dll
Microsoft.Azure.PowerShell.Authentication.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Authentication.ResourceManager.dll
Microsoft.Azure.PowerShell.Clients.Authorization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Authorization.dll
Microsoft.Azure.PowerShell.Clients.Compute, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Compute.dll
Microsoft.Azure.PowerShell.Clients.Graph.Rbac, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Graph.Rbac.dll
Microsoft.Azure.PowerShell.Clients.Monitor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Monitor.dll
Microsoft.Azure.PowerShell.Clients.Network, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Network.dll
Microsoft.Azure.PowerShell.Clients.PolicyInsights, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.PolicyInsights.dll
Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.ResourceManager.dll
Microsoft.Azure.PowerShell.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Common.dll
Microsoft.Azure.PowerShell.Storage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Storage.dll
Microsoft.Azure.PowerShell.Clients.Storage.Management, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Storage.Management.dll
Microsoft.Azure.PowerShell.Clients.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.KeyVault.dll
Microsoft.Azure.PowerShell.Clients.Websites, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Websites.dll
Hyak.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Hyak.Common.dll
Microsoft.ApplicationInsights, Version=2.12.0.21496, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.ApplicationInsights.dll
Microsoft.Azure.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.Common.dll
Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Rest.ClientRuntime.dll
Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Rest.ClientRuntime.Azure.dll
Microsoft.WindowsAzure.Storage, Version=9.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.WindowsAzure.Storage.dll
Microsoft.WindowsAzure.Storage.DataMovement, Version=0.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.WindowsAzure.Storage.DataMovement.dll
Microsoft.Azure.PowerShell.Clients.Aks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Clients.Aks.dll
Microsoft.Azure.PowerShell.Strategies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Strategies.dll
Microsoft.Azure.PowerShell.Common.Share, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Common.Share.dll
Microsoft.PowerShell.Commands.Management, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Management\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Management.dll
Microsoft.WSMan.Management, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.WSMan.Management\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.WSMan.Management.dll
System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll
System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll
netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\netstandard\v4.0_2.0.0.0__cc7b13ffcd2ddd51\netstandard.dll
Azure.Core, Version=1.21.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Azure.Core.dll
Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Microsoft.Bcl.AsyncInterfaces.dll
System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Text.Json.dll
System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Memory.dll
System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Threading.Tasks.Extensions.dll
System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ValueTuple\v4.0_4.0.0.0__cc7b13ffcd2ddd51\System.ValueTuple.dll
System.Memory.Data, Version=1.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Memory.Data.dll
System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll
System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Diagnostics.DiagnosticSource.dll
System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll
Azure.Identity, Version=1.5.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Azure.Identity.dll
Microsoft.Identity.Client, Version=4.30.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Microsoft.Identity.Client.dll
Microsoft.Identity.Client.Extensions.Msal, Version=2.18.4.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Microsoft.Identity.Client.Extensions.Msal.dll
Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Newtonsoft.Json.12.0.3.dll
Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\Newtonsoft.Json.dll
System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Buffers.dll
System.Diagnostics.Tracing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Diagnostics.Tracing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Diagnostics.Tracing.dll
System.Net.Http.WinHttpHandler, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Net.Http.WinHttpHandler.dll
System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Numerics.Vectors.dll
System.Reflection.DispatchProxy, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Reflection.DispatchProxy.dll
System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Runtime.CompilerServices.Unsafe.dll
System.Security.AccessControl, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Security.AccessControl.dll
System.Security.Cryptography.Cng, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Security.Cryptography.Cng.dll
System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Security.Permissions.dll
System.Security.Principal.Windows, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Security.Principal.Windows.dll
System.Text.Encodings.Web, Version=4.0.5.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\PreloadAssemblies\System.Text.Encodings.Web.dll
System.Xml.ReaderWriter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.ReaderWriter\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Xml.ReaderWriter.dll
Microsoft.Azure.PowerShell.Cmdlets.Accounts, Version=2.7.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.7.2\Microsoft.Azure.PowerShell.Cmdlets.Accounts.dll
System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.InteropServices.RuntimeInformation\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.InteropServices.RuntimeInformation.dll
System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll
System.Threading, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Threading\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.dll
System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Collections\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.dll
System.Data.SqlXml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.SqlXml\v4.0_4.0.0.0__b77a5c561934e089\System.Data.SqlXml.dll
System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll
Windows.ApplicationModel, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.ApplicationModel.winmd
Windows.System, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.System.winmd
Windows.Devices, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.Devices.winmd
Windows.Media, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.Media.winmd
System.Numerics.Vectors, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics.Vectors\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Numerics.Vectors.dll
Windows.Graphics, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.Graphics.winmd
Windows.Storage, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.Storage.winmd
Windows.Security, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime C:\Windows\system32\WinMetadata\Windows.Security.winmd
System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll
System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Threading.Tasks\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.Tasks.dll
PresentationFramework-SystemXmlLinq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll
System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Primitives\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Primitives.dll
System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Linq.Expressions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Linq.Expressions.dll
System.Text.RegularExpressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Text.RegularExpressions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Text.RegularExpressions.dll
System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IO\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.IO.dll
System.IO.FileSystem.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IO.FileSystem.Primitives\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.IO.FileSystem.Primitives.dll
System.Runtime.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Extensions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Extensions.dll
System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Globalization\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Globalization.dll
System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll
System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll
System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll
System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll
System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll
System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll
Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Framework\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Framework.dll
SMDiagnostics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll
System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll
@TrondHaugmo apologies for the delayed response. I tried to reproduce the issue based on all the scenarios you had highlighted, and none yielded results similar to yours. The connection was successful without any errors. However, I've noticed that the AZ module version you are using is quite old and may cause conflicts. Maybe you can consider updating it.
I also receive same error, after logging in using Azure AD Administrator account, grant permissions in the consent screen.
Connect-MgGraph: The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception.
Powershell : 7.0.2 Microsoft.Graph.Authentication : 2.6.1 Microsoft.Graph: 2.6.1
@unnieayilliath please confirm the Az module version you are using. If its an old version, consider upgrading to the latest version.
@unnieayilliath please confirm the Az module version you are using. If its an old version, consider upgrading to the latest version.
I dont' have Az module installed on this machine.
Hello @timayabi2020, I apologize for the delayed response after you recommended updating Az-modules on the machine in question. Another task with even higher priority (according to my manager) has unfortunately taken all my time (day and night) the last few days. However, today I have focused on this challenge again, and it looks like you really "hit the nail on the head" with putting focus on the Az-modules. We use cmdlets from them quite regularly on the machine in question, but since they have just worked lately we have been a bit lazy and not updated them for a while.
Today I performed some "housekeeping" and updated all Az-modules to the most recent version (main version 10.4.1, lot of different individual versions on each of the detailed modules), removed any old module versions in the process as well, and then also installed the very latest Microsoft.Graph modules (2.6.1), after first removing the Beta-version which was installed in an earlier attempt to find a solution. With this "setup" (and the required Azure AD/Entra ID roles activated through PIM) I was successfully able to run Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
, which this time gave what I guess is the expected output:
Welcome to Microsoft Graph!
Connected via delegated access using 14d82eec-204b-4c2f-b7e8-296a70dab67e
Readme: https://aka.ms/graph/sdk/powershell
SDK Docs: https://aka.ms/graph/sdk/powershell/docs
API Docs: https://aka.ms/graph/docs
NOTE: You can use the -NoWelcome parameter to suppress this message.
PS C:\Windows\system32>
I could also execute commands and make updates to Azure AD/Entra ID resources through for example the use of the Remove-MgGroup
cmdlet. So, then this does not seem like an issue with the Microsoft.Graph PS modules after all, but some form of race-condition in combination with old Az-modules I guess?
Still having the issue even with the latest Az module version and the latest Graph module. If both are used in the same file, there'll be errors. I am getting errors on both Powershell 5.1 and 7.0.
Yes, I am still facing the same issue:
Connect-MgGraph : The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception.
I have the same problem here:
I enabled defender for Identity in Azure then these commands stopped working for mggraph.
PS C:\Windows\system32> Import-Module Microsoft.Graph.Authentication
Import-Module : Could not load file or assembly 'Azure.Core, Version=1.33.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified. At line:1 char:1
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
PS C:\Windows\system32> Update-Module Microsoft.Graph
PS C:\Windows\system32> Import-Module Microsoft.Graph.Authentication
Import-Module : Could not load file or assembly 'Azure.Core, Version=1.33.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified. At line:1 char:1
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
PS C:\Windows\system32>
Found a solution:
when installing the modules, add -force at the end to update the module to a working version.
do the following: Update-Module Microsoft.Graph install-module Microsoft.Graph.Users.Actions -Force install-module Microsoft.Graph.Authentication -Force install-module Microsoft.Graph.mail -Force
Then try importing. it should work after that.
Using latest version of Microsoft.Graph. MS.Graph.Authentication is version 2.23.0.
$TenantId = "XYZ"
$SpnName = "ABC"
Update-AzConfig -EnableLoginByWam $false -LoginExperienceV2 Off
Connect-AzAccount -Tenant $TenantId
$oApp = Get-AzADApplication -DisplayName $SpnName
$oCred = Get-Credential -Credential $oApp.AppId
Import-Module -Name Microsoft.Graph.Authentication -Force
Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $oCred -NoWelcome
Connect-MgGraph line results in:
Connect-MgGraph: Entry point was not found.
If I just run Connect-MgGraph -TenantId $TenantId
, I get:
Connect-MgGraph: Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.
It appears to be related to the PowerShell extension for VSCode. Kill the terminal and launch a fresh pwsh
terminal and all is good.
It appears to be related to the PowerShell extension for VSCode. Kill the terminal and launch a fresh
pwsh
terminal and all is good.
Not here, I am runing powershell 5.1, I have uninstalled vscode-powershell just for test:
PS C:\> import-module Microsoft.Graph.Authentication
PS C:\ [1,78s]> Connect-AzAccount
Please select the account you want to login with.
ADVERTENCIA: Unable to acquire token for tenant 'organizations' with error 'Método no encontrado: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord>
Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.'
Connect-AzAccount : Método no encontrado: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext,
System.Threading.CancellationToken)'.
PS C:\ [9,34s]> get-module -ListAvailable Az.Accounts,Microsoft.Graph.Authentication
Directorio: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 3.0.4 Az.Accounts {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}
Script 2.24.0 Microsoft.Graph.Authentication {Connect-MgGraph, Disconnect-MgGraph, Get-MgContext, Invoke-MgGraphRequest...}
We are trying to start using the Microsoft.Graph PS modules for our Azure AD scripting needs, but even after installing the very latest versions of the modules (now also having tried the latest beta versions) on my system, I still get an error stating "The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception" (TypeInitializationException) when running "Connect-MgGraph".
We have opened a support call through our Unified Support Agreement (Case tracking ID: 2307070050003124), but after working with the support technician for a while (which have had us report on what are the currently installed Microsoft.Graph modules and requested us to fully remove them and then install the very latest versions including the most recent beta version in several "rounds") we are still consistently getting the same error every time we try to run Connect-MgGraph, and the support technician has thus recommended us to also register this as an issue here on GitHub.
This is the command we try to run, which obviously brings up a prompt to perform authentication: Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
I authenticate with my Azure AD admin account which has the following AD roles activated (through PIM) in advance of running the command:
The authentication is successful it seems, and the very first time we tried this we also had to go through an admin-consent process, but that now seems properly registered in our Azure AD tenant as that does not show up after that first attempt. Now we just go through MFA and then the authentication dialog briefly states that authentication was successful before it close. However, immediately after we get the mentioned error as you can see in the example screenshot below:
The machine where I'm encountering the issue is running Windows Server 2016 with PowerShell 5.1 (see version details below). The support technician has recommended us to try using PowerShell 7.x, but for various reasons we cannot introduce that version of PowerShell on the system in question, and the Microsoft.Graph modules are officially supported also on PowerShell 5.1 so we need to figure out why it does not work in our case. The output from $PSVersionTable on the system looks like this:
Reproducing the issue Full set of steps that reproduce the behavior:
Get-Module
to show what modules are automatically loaded:Get-Module -FullyQualifiedName Microsoft.Graph* -ListAvailable
to verify that I only have one set of Microsoft.Graph modules installed, and as you can see from the screenshot below it is now the beta-edition of the most recent version (2.4.0) that are installed on the system:Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
and after completing the authentication including MFA through the pop-up dialog, then the error is immediately encountered:Expected behavior The expected behavior is that executing
Connect-MgGraph
would complete successfully without returning an error.Debug Output I have also tried running the
Connect-MgGraph
cmdlet with the same parameters, but also adding-Debug
, and the full output of that looks like this (requestID's/correlationId's anonymized):DEBUG: InteractiveBrowserCredential.Authenticate invoked. Scopes: [ User.Read.All, Group.ReadWrite.All ] ParentRequestId: DEBUG: Executing interactive authentication workflow inline. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:52Z - x1111111-xxxx-11xx- 8f64-71f2f9addfaf] MSAL MSAL.Desktop with assembly version '4.49.1.0'. CorrelationId( x1111111-xxxx-11xx-8f64-71f2f9addfaf ) DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === InteractiveParameters Data === LoginHint provided: False User provided: False UseEmbeddedWebView: NotSpecified ExtraScopesToConsent: Prompt: select_account HasCustomWebUi: False
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === Request Data === Authority Provided? - True Scopes - User.Read.All Group.ReadWrite.All Extra Query Params Keys (space separated) - ApiId - AcquireTokenInteractive IsConfidentialClient - False SendX5C - False LoginHint ? False IsBrokerConfigured - False HomeAccountId - False CorrelationId - x1111111-xxxx-11xx-8f64-71f2f9addfaf UserAssertion set: False LongRunningOboCacheKey set: False Region configured:
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === Token Acquisition (InteractiveRequest) started: Scopes: User.Read.All Group.ReadWrite.All Authority Host: login.microsoftonline.com DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Instance Discovery] Instance discovery is enabled and will be performed DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Fetching instance discovery from the network from host login.microsoftonline.com. DEBUG: Request [xxx1111x-1xx1-111x-99c3-58188404c787] GET https://login.microsoftonline.com/common/discovery/instance?api-v ersion=1.1&authorization_endpoint=REDACTED x-client-SKU:REDACTED x-client-Ver:REDACTED x-client-CPU:REDACTED x-client-OS:REDACTED client-request-id:REDACTED return-client-request-id:REDACTED x-app-name:REDACTED x-app-ver:REDACTED x-ms-client-request-id:xxx1111x-1xx1-111x-99c3-58188404c787 x-ms-return-client-request-id:true User-Agent:azsdk-net-Identity/1.9.0 (.NET Framework 4.8.4645.0; Microsoft Windows 10.0.14393 ) client assembly: Azure.Identity DEBUG: Response [xxx1111x-1xx1-111x-99c3-58188404c787] 200 OK (00.1s) Strict-Transport-Security:REDACTED X-Content-Type-Options:REDACTED Access-Control-Allow-Origin:REDACTED Access-Control-Allow-Methods:REDACTED client-request-id:REDACTED x-ms-request-id:111111xx-1111-1xx1-84b9-cf2e18138a00 x-ms-ests-server:REDACTED X-XSS-Protection:REDACTED Cache-Control:max-age=86400, private Content-Type:application/json; charset=utf-8 P3P:REDACTED Set-Cookie:REDACTED Date:Mon, 04 Sep 2023 07:37:56 GMT Content-Length:950
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Authority validation enabled? True. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Authority validation - is known env? True. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Using legacy embedded browser. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Legacy WebView] Redirect URI was reached. Stopping WebView navigation... DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] An authorization code was retrieved from the /authorize endpoint. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Exchanging the auth code for tokens. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === InteractiveParameters Data === LoginHint provided: False User provided: False UseEmbeddedWebView: NotSpecified ExtraScopesToConsent: Prompt: select_account HasCustomWebUi: False
DEBUG: Request [1111x11x-1111-1111-9096-cf017e3724e1] POST https://login.microsoftonline.com/common/oauth2/v2.0/token x-client-SKU:REDACTED x-client-Ver:REDACTED x-client-CPU:REDACTED x-client-OS:REDACTED x-anchormailbox:REDACTED x-client-current-telemetry:REDACTED x-client-last-telemetry:REDACTED x-ms-PKeyAuth:REDACTED x-ms-lib-capability:REDACTED client-request-id:REDACTED return-client-request-id:REDACTED x-app-name:REDACTED x-app-ver:REDACTED Content-Type:application/x-www-form-urlencoded x-ms-client-request-id:1111x11x-1111-1111-9096-cf017e3724e1 x-ms-return-client-request-id:true User-Agent:azsdk-net-Identity/1.9.0 (.NET Framework 4.8.4645.0; Microsoft Windows 10.0.14393 ) client assembly: Azure.Identity DEBUG: Response [1111x11x-1111-1111-9096-cf017e3724e1] 200 OK (00.3s) Pragma:no-cache Strict-Transport-Security:REDACTED X-Content-Type-Options:REDACTED client-request-id:REDACTED x-ms-request-id:11xxx1xx-1111-111x-b139-4628de696700 x-ms-ests-server:REDACTED x-ms-clitelem:REDACTED X-XSS-Protection:REDACTED Cache-Control:no-store, no-cache Content-Type:application/json; charset=utf-8 Expires:-1 P3P:REDACTED Set-Cookie:REDACTED Date:Mon, 04 Sep 2023 07:38:19 GMT Content-Length:5460
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Checking client info returned from the server.. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Saving token response to cache.. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [SaveTokenResponseAsync] Saving AT in cache and removing overlapping ATs... DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Looking for scopes for the authority in the cache which intersect with User.Read.All Group.ReadWrite.All DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Intersecting scope entries count - 1 DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Matching entries after filtering by user - 1 DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [SaveTokenResponseAsync] Saving Id Token and Account in cache ... DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [SaveTokenResponseAsync] Saving RT in cache... DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] IsLegacyAdalCacheEnabled: yes DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [AdalCacheOperations] Serializing token cache with 1 items. DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === Token Acquisition finished successfully: DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] AT expiration time: 9/5/2023 7:38:19 AM +00:00, scopes: Application.Read.All AuditLog.Read.All CrossT enantInformation.ReadBasic.All Group.Read.All Group.ReadWrite.All openid Policy.Read.All profile RoleAssignmentSchedule.Rea d.Directory RoleEligibilitySchedule.Read.Directory RoleManagement.Read.Directory User.Read User.Read.All email. source: Ide ntityProvider DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Fetched access token from host login.microsoftonline.com. DEBUG: InteractiveBrowserCredential.Authenticate succeeded. Scopes: [ User.Read.All, Group.ReadWrite.All ] ParentRequestId: ExpiresOn: 2023-09-05T07:38:19.8408559+00:00 Connect-MgGraph : The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception. At line:1 char:1
Module Version