Connect-MgGraph : Invalid JWT access token. Connect-AzAccount : InteractiveBrowserCredential authentication failed

EnterpriseArchitect 4,916 Reputation points
2024-05-28T07:17:43.8466667+00:00

I need help and a solution to rectify the below error when executing the PowerShell Connect-* command.

$TenantID = '22bb9241-65c8-45b4-94f9-7c151e154693'
$AzSubscriptionID = 'd487514e-4317-447f-af79-5022d310f6bd'

$paramConnectMgGraph = @{
	Scopes     = 'User.ReadWrite.All', 'Group.ReadWrite.All', 'Directory.ReadWrite.All',	'UserAuthenticationMethod.Read.All'$RequiredScopes
	TenantId   = $TenantID
	NoWelcome  = $true
}
Update-AzConfig -DefaultSubscriptionForLogin $AzSubscriptionID
Connect-AzAccount -Tenant $TenantID -Verbose
Connect-MgGraph @paramConnectMgGraph
Get-Module *Az *Graph*
$PSVersionTable | ft -AutoSize

The script consistently throws errors, even though it is executed as a Local Administrator with the appropriate permissions granted.

Connect-AzAccount : InteractiveBrowserCredential authentication failed: A window handle must be configured. See https://aka.ms/msal-net-wam#parent-window-handles
Could not find the tenant ID for the provided tenant domain '22bb9241-65c8-45b4-94f9-7c151e154693'. Please ensure that the provided user is found in the provided tenant domain.
At line:17 char:1
+ Connect-AzAccount -Tenant $TenantID -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Connect-AzAccount], ArgumentNullException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
 
Connect-MgGraph : Invalid JWT access token.
At line:18 char:1
+ Connect-MgGraph @paramConnectMgGraph
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-MgGraph], AuthenticationException
    + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph


ModuleType Version    Name                                ExportedCommands                                                                                                                                           
---------- -------    ----                                ----------------                                                                                                                                           
Script     3.0.0      Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}                                                                                   
Binary     2.0.2.182  AzureAD                             {Add-AzureADApplicationOwner, Add-AzureADDeviceRegisteredOwner, Add-AzureADDeviceRegisteredUser, Add-AzureADDirectoryRoleMember...}                        
Script     2.19.0     Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext...} 


Name                      Value                  
----                      -----                  
PSVersion                 5.1.20348.2400         
PSEdition                 Desktop                
PSCompatibleVersions      {1.0, 2.0, 3.0, 4.0...}
BuildVersion              10.0.20348.2400        
CLRVersion                4.0.30319.42000        
WSManStackVersion         3.0                    
PSRemotingProtocolVersion 2.3                    
SerializationVersion      1.1.0.1    

Any help would be greatly appreciated.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,087 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,432 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,223 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 475 Reputation points Microsoft Vendor
    2024-05-28T12:31:08.25+00:00

    Hello @EnterpriseArchitect,

    Thank you for contacting Microsoft Support!!

    Try to install AZ module on your PowerShell and set your execution policy to remote signed. If you have already installed, please uninstall the modules or update the modules.

    I was able to replicate the issue from my end and followed the below PS commands and it worked. Once, this is done everything should work as expected.

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

    Install-Module Az -Scope CurrentUser

    Connect-AzAccount -DeviceCode -Tenant $TenantID

    Please refer to this document for installing the Azure PowerShell module. Refer to this document for setting your execution policy to RemoteSigned.

    After setting your execution policy to remote signed and updating Graph Modules in PowerShell, Connect-MgGraph should also work as expected.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".