Connect-MgGraph - Object reference not set to an instance of an object. when using -ClientId
I'm attempting to authentication using the clinetId for my app registration.
My command for the connection is
Connect-MgGraph -Scopes "User.Read","Group.Read.All" -ClientId "$ClientId" -TenantId "$TenantId"
Everything starts as expected my browser opens and I authenticate with my account but then I receive an error in my terminal.
Connect-MgGraph: Object reference not set to an instance of an object.
I'm not sure if I'm missing some required parameter. Or a setting in my app registration? When I run the command with using only the -TenantId and -Scopes parameters it works as expected but using the generic Graph app.
I'm not able to repo this on my end using the latest version of the module (1.11.1):

Please share the out of the following for us to try repro this behavior:
-
Get-Module Microsoft.Graph.Authentication -
$PSVersionTable - Detailed repro steps. e.g., what steps did you do before invoking
Connect-MgGraph.
Also, could you go through the steps at https://github.com/microsoftgraph/msgraph-sdk-powershell#known-issues to clear you token cache to see if this helps.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
I have the exact same issue. Also removing and installing Microsoft.Graph did not help.

I was getting this same error trying to use a registered app with Connect-MGGraph, but fixed the issue by changing the redirectURI's in my AzureAD application from type "Web" to "Mobile and desktop applications". It also appeared to need the same URIs that are suggested by the OAUTH prompt depending on whether you are using Windows PowerShell 5.1 or PowerShell 7x. Hope that helps get you going. 👍