App Registration for Microsoft Graph
* Think Service Account, not user account *
Permissions Requested
Required API Permissions
Directory.Read.All
User.Read.All
Group.ReadWrite.All
DeviceManagementManagedDevices.Read.All
DeviceManagementConfiguration.Read.All
DeviceManagementApps.ReadWrite.All
DeviceManagementApps.Read.All
DeviceManagementManagedDevices.PrivilegedOperations.All
DeviceManagementManagedDevices.ReadWrite.All
DeviceManagementManagedDevices.Read.All
DeviceManagementRBAC.ReadWrite.All
DeviceManagementRBAC.Read.All
DeviceManagementConfiguration.ReadWrite.All
DeviceManagementConfiguration.Read.All
DeviceManagementServiceConfig.ReadWrite.All
DeviceManagementServiceConfig.Read.All
Steps for Setup
This example is the app registration has the permission, not the user connecting. This is for Azure AD and Intune. You can add others if needed. But you need to download the token again if you change permission (scopes).
Logon to Azure AD (Entra) as a Global Admin, go to app registrations
Create (Register) and new app
Give it a name, the redirect is not applicable but needs a URI to continue
Go to the app permissions and add in, see following
Graph access
User accounts in Azure AD
See above for all permissions
See the status has changed, if you add permission you may need this again
Go to Managed Applications and grant access to the end user account using this API
Add user
Select ‘none selected’ – great interface naming
Find your users
Create a secret for the client to connect
Create one, this can be replaced and re-shared if it has leaked
Give it the time frame for renewal
Copy the VALUE now of you will need to re-create it as it is hidden when you return Creation:
Future:
Testing
Connect to the API # Tenant ID for your Azure AD instance
$tenantId = 'xxx'
# Your application (client) ID
$appId = 'xxxx' # Application (client) ID
# Your application (client) secret value
$appSecret = 'xxx' #Value
# scope list for access token (for user delegated permissions)
# $scopes = "User.Read.All Mail.Read Files.read.all User.Read"
# the user I am looking at for the onedrive details etc (not the logged on user)
$userId = 'Dave.Colvin@workplace.onmicrosoft.com'
$body = @{
grant_type = "client_credentials"
scope = "https://graph.microsoft.com/.default"
client_id = $appId
client_secret = $appSecret
}
$response = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -Body $body -ContentType "application/x-www-form-urlencoded"
$token = $response.access_token
# connecting as the application with the permission on the service
Connect-MgGraph -AccessToken ($Token |ConvertTo-SecureString -AsPlainText -Force)
(get-mgcontext).Scopes
Permissions for Intune API
Intune permission scopes
Perform user-impacting remote actions on Microsoft Intune devices
DeviceManagementManagedDevices.PrivilegedOperations.All
Read and write Microsoft Intune devices DeviceManagementManagedDevices.ReadWrite.All
Read Microsoft Intune devices DeviceManagementManagedDevices.Read.All
Read and write Microsoft Intune RBAC settings DeviceManagementRBAC.ReadWrite.All
Read Microsoft Intune RBAC settings DeviceManagementRBAC.Read.All
Read and write Microsoft Intune apps DeviceManagementApps.ReadWrite.All
Read Microsoft Intune apps DeviceManagementApps.Read.All
Read and write Microsoft Intune Device Configuration and Policies DeviceManagementConfiguration.ReadWrite.All
Read Microsoft Intune Device Configuration and Policies DeviceManagementConfiguration.Read.All
Read and write Microsoft Intune configuration DeviceManagementServiceConfig.ReadWrite.All
Read Microsoft Intune configuration DeviceManagementServiceConfig.Read.All
Permissions Explained
DeviceManagementApps.Read.All
• Enable Access setting: Read Microsoft Intune apps
• Permits read access to the following entity properties and status:
o Client Apps
o Mobile App Categories
o App Protection Policies
o App Configurations
DeviceManagementApps.ReadWrite.All
• Enable Access setting: Read and write Microsoft Intune apps
• Allows the same operations as DeviceManagementApps.Read.All
• Also permits changes to the following entities:
o Client Apps
o Mobile App Categories
o App Protection Policies
o App Configurations
DeviceManagementConfiguration.Read.All
• Enable Access setting: Read Microsoft Intune device configuration and policies
• Permits read access to the following entity properties and status:
o Device Configuration
o Device Compliance Policy
o Notification Messages
DeviceManagementConfiguration.ReadWrite.All
• Enable Access setting: Read and write Microsoft Intune device configuration and policies
• Allows the same operations as DeviceManagementConfiguration.Read.All
• Apps can also create, assign, delete, and change the following entities:
o Device Configuration
o Device Compliance Policy
o Notification Messages
DeviceManagementManagedDevices.PrivilegedOperations.All
• Enable Access setting: Perform user-impacting remote actions on Microsoft Intune devices
• Permits the following remote actions on a managed device:
o Retire
o Wipe
o Reset/Recover Passcode
o Remote Lock
o Enable/Disable Lost Mode
o Clean PC
o Reboot
o Delete User from Shared Device
DeviceManagementManagedDevices.Read.All
• Enable Access setting: Read Microsoft Intune devices
• Permits read access to the following entity properties and status:
o Managed Device
o Device Category
o Detected App
o Remote actions
o Malware information
DeviceManagementManagedDevices.ReadWrite.All
• Enable Access setting: Read and write Microsoft Intune devices
• Allows the same operations as DeviceManagementManagedDevices.Read.All
• Apps can also create, delete, and change the following entities:
o Managed Device
o Device Category
• The following remote actions are also allowed:
o Locate devices
o Disable Activation Lock
o Request remote assistance
DeviceManagementRBAC.Read.All
• Enable Access setting: Read Microsoft Intune RBAC settings
• Permits read access to the following entity properties and status:
o Role Assignments
o Role Definitions
o Resource Operations
DeviceManagementRBAC.ReadWrite.All
• Enable Access setting: Read and write Microsoft Intune RBAC settings
• Allows the same operations as DeviceManagementRBAC.Read.All
• Apps can also create, assign, delete, and change the following entities:
o Role Assignments
o Role Definitions
DeviceManagementServiceConfig.Read.All
• Enable Access setting: Read Microsoft Intune configuration
• Permits read access to the following entity properties and status:
o Device Enrollment
o Apple Push Notification Certificate
o Apple Device Enrollment Program
o Apple Volume Purchase Program
o Exchange Connector
o Terms and Conditions
o Cloud PKI
o Branding
o Mobile Threat Defense
DeviceManagementServiceConfig.ReadWrite.All
• Enable Access setting: Read and write Microsoft Intune configuration
• Allows the same operations as DeviceManagementServiceConfig.Read.All_
• Apps can also configure the following Intune features:
o Device Enrollment
o Apple Push Notification Certificate
o Apple Device Enrollment Program
o Apple Volume Purchase Program
o Exchange Connector
o Terms and Conditions
o Cloud PKI
o Branding
o Mobile Threat Defense