Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Determine What Microsoft Graph Permissions You Need to Connect

September 15, 2023
in Blog, Microsoft Graph, Powershell
0
ADVERTISEMENT

Table of Contents

What is a Microsoft Graph scope?

For many admins, the use of Scopes is a new addition to Office 365 PowerShell. The Scopes parameter was introduced with the Microsoft Graph PowerShell API, but the concept of Scopes is actually part of the OAuth2 specification.

PS C:\> Connect-MgGraph
Welcome To Microsoft Graph!

The use of Scopes limits the user permissions available to an application or session.

By configuring Scopes when connecting to the Microsoft Graph PowerShell API, you effectively limit what permissions are available for the execution of commands. We’ll see this in a live example further down.

Connecting to MS Graph With Scopes

For example, you want to run a script that exports some user information from the Microsoft 365 Graph. Since you’ll only be reading user information, it makes good sense to limit your permissions to read-only (principle of least privilege).

Connect-MgGraph -Scopes "User.Read.All"

This will ensure that you don’t accidentally make updates to user accounts. Also, it protects you from a rogue application trying to make changes when it should only be reading information. This will cause OAuth2 authentication to kick in (unless you have already consented to the permissions requested in the Scopes parameter):

TmNGpxTXVaO2tDeGtbtlRwf9mxaOyRsSxcOVaRFsdLeL2HZ0oYubDtPKzJUb

Notice that you can clearly see what permissions you’re allowing the Microsoft Graph PowerShell application to use. In this case, the app only has read permissions to all accounts.

Note Keep in mind: Consent does not grant any new permissions to users in your organization. Consent only allows the application (in this case, Microsoft Graph PowerShell) to use permissions already assigned to users.

After you accept the permissions request, the Microsoft Graph PowerShell application is configured with the new consent. Go to Enterprise Applications > Microsoft Graph Command Line Tools > Permissions > User consent to see it:

AU5tRy3N3R57Vv020xRuhsPynU0kdqZjeqEmC7Fkl4teHMK6GlW6B1VIyq1G

When you’ve connected to Microsoft Graph, you can check the current permission is granted for the current session by using the Get-MgContext cmdlet:

PS C:\> (Get-MgContext).scopes
openid
profile
User.Read.All
email

To illustrate the protection received by using scopes configuration, let’s try to update an Entra ID user account by setting the UsageLocation attribute. We connect with Scopes set to User.Read.All and as expected, this fails:

PS C:\> Get-MgUser -UserId [email protected] -Property DisplayName,UsageLocation

DisplayName UsageLocation
----------- -------------
Alex Wilber US

PS C:\> Update-MgUser -UserId [email protected] -UsageLocation "UK"

Update-MgUser : Insufficient privileges to complete the operation.
Status: 403 (Forbidden)
ErrorCode: Authorization_RequestDenied
Date: 2023-08-21T00:26:06
Headers:
Transfer-Encoding : chunked
…

To fix this we have to reconnect using a more extensive scope. With the new scope, you can now the write permission on all user accounts on your tenant.

Connect-MgGraph -Scopes "User.ReadWrite.All"

Assuming we haven’t previously consented to this, we receive a new OAuth2 authentication dialog stating the new level of consent. This time, the app requires the read and write permission.

7sqQuUGLjqUxCtdxtmoIk9ZeqVf73j5wwkJ3YUPtxJYFwdaHnKmrRzrWAV6y

Once connected, when you check the MgContext, the new permission should be added.

PS C:\> (Get-MgContext).Scopes
openid
profile
User.Read.All
email
User.ReadWrite.All

After accepting this, the User consent of the Microsoft Graph PowerShell Enterprise Application is updated with the new consent which we can verify in the Azure Portal:

gAyhdDolalHjKS0qCJNWlYRqHLogLDmDpV1GWjiNnaCg1BjxN3BZrQ0QfisK

With the new scope in place, we are now able to write new information to user objects in Entra ID:

PS C:\> Update-MgUser -UserId [email protected] -UsageLocation "VN"
PS C:\> Get-MgUser -UserId [email protected] -Property DisplayName,UsageLocation

DisplayName UsageLocation
----------- -------------
Alex Wilber VN
PS C:\> (Find-MgGraphCommand -Command 'New-MgDomain').Permissions

Name                 IsAdmin Description
----                 ------- -----------
Domain.ReadWrite.All    True Read and write domains

Finding Microsoft Graph Scopes

Finding the right scope can be a bit challenging at the beginning. But there are some good sources that you can use to determine which scopes you will need to specify:

  • Microsoft Graph Explorer: https://developer.microsoft.com/en-us/graph/graph-explorer
  • Microsoft Graph Rest API Reference: https://docs.microsoft.com/en-us/graph/api/overview
  • Find-MgGraphCommand, Find-MgGraphPermission cmdlets.

Microsoft Graph Explorer

The Microsoft Graph Explorer is a great tool to test out API calls to Microsoft Graph. It comes with a lot of examples calls to help you get started. But it will also list the required permission for the call.

Open the Graph Explorer | Select an Sample Query on the left side | Click Modify Permissions tab.

Bg1266

Microsoft Graph Rest API Reference

The other option is to use the Rest API Reference. You can select in the left menu one of the entities that you want to work with and then view the required permissions. You don’t need to add all scope, they are listed from least to most privileged.

An example, we find the scope to get OneDrive for Business for users.

Bg1267

Find-MgGraphCommand

Our favorite way to find the right scopes to connect to Microsoft Graph PowerShell is using Find-MgGraphCommand cmdlet.

For example, we found the right permission to update users’ information with Update-MgUser cmdlet.

(Find-MgGraphCommand -Command 'Update-MgUser').Permissions
Name                                         IsAdmin Description
----                                         ------- -----------
DeviceManagementApps.ReadWrite.All              True Read and write Microsoft Intune apps
DeviceManagementConfiguration.ReadWrite.All     True Read and write Microsoft Intune Device
DeviceManagementManagedDevices.ReadWrite.All    True Read and write Microsoft Intune devices
DeviceManagementServiceConfig.ReadWrite.All     True Read and write Microsoft Intune configuration
Directory.ReadWrite.All                         True Read and write directory data
User.EnableDisableAccount.All                   True Enable and disable user accounts
User.ManageIdentities.All                       True Manage  user identities
User.ReadWrite                                 False Read and update your profile
User.ReadWrite.All                             False Read and write all users' full profiles

Find the required permissions to create a new user using Microsoft Graph.

PS C:\> (Find-MgGraphCommand -Command 'New-MgUser').Permissions

Name                                         IsAdmin Description
----                                         ------- -----------
DeviceManagementApps.ReadWrite.All              True Read and write Microsoft Intune apps
DeviceManagementConfiguration.ReadWrite.All     True Read and write Microsoft Intune Device 
DeviceManagementManagedDevices.ReadWrite.All    True Read and write Microsoft Intune devices
DeviceManagementServiceConfig.ReadWrite.All     True Read and write Microsoft Intune 
Directory.ReadWrite.All                         True Read and write directory data
User.ReadWrite.All                              True Read and write all users' full profiles

Find the permissions to create or add a new domain into Microsoft 365 tenant using Microsoft Graph.

PS C:\> (Find-MgGraphCommand -Command 'New-MgDomain').Permissions

Name                 IsAdmin Description
----                 ------- -----------
Domain.ReadWrite.All    True Read and write domains

The required permissions to create a new Teams group.

PS C:\> (Find-MgGraphCommand -Command 'New-MgTeam').Permissions

Name                    IsAdmin Description
----                    ------- -----------
Directory.ReadWrite.All    True Read and write directory data
Group.ReadWrite.All        True Read and write all groups
Team.Create               False Create teams

The permission to get the list of devices in your organization.

PS C:\> (Find-MgGraphCommand -Command 'Get-MgDevice').Permissions 

Name                    IsAdmin Description
----                    ------- -----------
Device.Read.All            True Read all devices
Directory.Read.All         True Read directory data
Directory.ReadWrite.All    True Read and write directory data

The permissions need to be assigned to get the list of Teams groups in your tenant.

PS C:\> (Find-MgGraphCommand -Command 'Get-MgTeam').Permissions 

Name                       IsAdmin Description
----                       ------- -----------
Directory.Read.All            True Read directory data
Directory.ReadWrite.All       True Read and write directory data
Group.Read.All                True Read all groups
Group.ReadWrite.All           True Read and write all groups
Team.ReadBasic.All           False Read the names and descriptions of teams
TeamSettings.Read.All         True Read teams' settings
TeamSettings.ReadWrite.All    True Read and change teams' settings

Additionally, you can use another Microsoft Graph PowerShell cmdlet to get the needed permissions to perform actions. Read more: How to Use Find-MgGraphPermission cmdlet in Microsoft Graph PowerShell

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Create Multiple Users in Microsoft 365 with Graph PowerShell

Next Post

You have Exceeded the Maximum Number of Allowable Transactions Microsoft 365

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory