Share via

Why Connect-MgGraph powershell commandlet requires scope parameter?

Rajesh Swarnkar 1,236 Reputation points
2024-03-06T12:48:43.21+00:00

May I know why (and whats the logic) behind having a scope parameter in Connect-MgGraph?

Works:

Connect-MgGraph -TenantId XXX -UseDeviceAuthentication -Scopes "User.Read.All"
$users = Get-MgUser

Doesn't Work:

Connect-MgGraph -TenantId XXX -UseDeviceAuthentication
$users = Get-MgUser
Get-MgUser_List: Insufficient privileges to complete the operation
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph

2 answers

Sort by: Most helpful
  1. Andy David - MVP 160.3K Reputation points MVP Volunteer Moderator
    2024-03-07T12:32:58.9866667+00:00

    I think was the poster is asking is, if he already has these delegated permissions, then why the need to add the scope parameter.

    The reason as I understand it is that using the scope switch indicates a delegated access request and so it technically required.

    https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#delegated-access

    But from what I have seen that is not always the case if you also are in an elevated role group that allows these actions.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Shweta Mathur 30,456 Reputation points Microsoft Employee Moderator
    2024-03-07T07:00:25.4466667+00:00

    Hi @Rajesh Swarnkar ,

    Thanks for reaching out.

    The Connect-MgGraph cmdlet acquires the access token through the Microsoft Authentication Library.

    While the notion of scopes aligns with the OAuth specification, the Scopes parameter was specifically incorporated into the Microsoft Graph PowerShell API to restrict the permissions granted to the application.

    Microsoft Graph serves as an encompassing platform for various modules, including Users, Groups, Apps, and the central module Microsoft.Graph.Authenticator.

    When you provide a scope, you're limiting your permissions to read-only, following the idea of least privilege. This helps prevent accidental changes to your accounts.

    Hope this will help.

    Thanks,

    Shweta

    Please remember to "Accept Answer" if answer helped you.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.