This blog walks you through the end-to-end process of granting a managed identity read/write access to a specific SharePoint Online site using Microsoft Graph and PowerShell.
Updated May 02, 2025
Version 1.0For System Assigned Managed Identities, the Sites.Selected scope can be enabled using Microsoft Graph PowerShell, as it is currently not possible to assign this permission directly from the Enterprise Applications UI.
PowerShell script:
Connect-MgGraph -Scopes "AppRoleAssignment.ReadWrite.All","Application.Read.All"
$managedIdentityObjectId = "<ManagedIdentityObjectId>"
$graphSp = Get-MgServicePrincipal -Filter "displayName eq 'Microsoft Graph'"
$sitesSelectedRole = $graphSp.AppRoles |
Where-Object {$_.Value -eq "Sites.Selected"}
$miSp = Get-MgServicePrincipal -Filter "id eq '$managedIdentityObjectId'"
New-MgServicePrincipalAppRoleAssignment `
-ServicePrincipalId $miSp.Id `
-PrincipalId $miSp.Id `
-ResourceId $graphSp.Id `
-AppRoleId $sitesSelectedRole.Id
After assigning the permission, you can grant SharePoint site-level access using:
New-MgSitePermission
This approach allows System Assigned Managed Identity to access SharePoint Online sites using Sites.Selected without requiring a separate App Registration.
Hope this helps others facing the same issue with managed identity and Sites.Selected assignment.