msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Connect-MgGraph - Object reference not set to an instance of an object. when using -ClientId

Open BigMcPatty opened this issue 3 years ago • 3 comments

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.

BigMcPatty avatar Sep 13 '22 17:09 BigMcPatty

I'm not able to repo this on my end using the latest version of the module (1.11.1): image

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.

peombwa avatar Sep 15 '22 17:09 peombwa

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.

ghost avatar Sep 19 '22 18:09 ghost

I have the exact same issue. Also removing and installing Microsoft.Graph did not help.

image

p-zim avatar Sep 22 '22 07:09 p-zim

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. 👍

GDKCTCS avatar Nov 15 '22 18:11 GDKCTCS