Here we will grant Graph API permissions to the managed identity or Run as account so it can access data from MS Graph.
We need to grant API permissions to the service principal object in Azure. For a managed identity, this can only be done with PowerShell at the time of writing.
Run the following PowerShell code to grant API permissions. You need the AzureAD module and Global administrator permissions.
Set the following variables in the script:
TenantID. This is the tenant ID for your tenant.
GraphAppId. You do not need to change this.
DisplayNameofMSI. The display name of your managed identity, which is the same as the name of your automation account.
Permissions. Here you can list which permissions you want to grant. You can reference the MS Docs to find the permissions you need. In this example, I have granted some Intune device management permissions ('DeviceManagement*') as well as some other Azure AD permissions.
Note these are application permissions not delegated permissions