If you give an Entra application Graph API access such ass Mail.Read, they will get that access to all mailboxes. This is usually too broad. You can also grant such accesses with a more limited scope. The below assumes you already have set up an app registration in Entra.
First, define an Administrative Unit in Entra, and add the mailboxes that should be accessible to it.
Then, define your app registration in Exchange with Exchange-PowerShell:
New-ServicePrincipal -AppId 978FFBA1-6F38-411C-BAD3-15B3DEC24D0E -ObjectId 5746492D-52FF-4501-8DF3-E7814C5491FA -DisplayName "Credit Insurance AI Summary Tool"
Note that the ObjectID must be the ObjectID displayed in the “Managed Application” in Entra. It differs from the ObjectID from the app registration.
Then, also using Exchange Powershell, bind together the service principal, the administrative unit, and a permission:
New-ManagementRoleAssignment -App 978FFBA1-6F38-411C-BAD3-15B3DEC24D0E -Role "Application Mail.Read" -RecipientAdministrativeUnitScope 9D3540C0-420A-48A9-8C72-BEE226F6C920
In this example, we're giving Mail.Read access to this application.
Finally, you can check any such management roles with this command. Your new role should be displayed:
Get-ManagementRoleAssignment -RoleAssigneeType ServicePrincipal
You can then validate if this works as intended by trying to access Graph API as your application. As an example:
# I first set a few parameters needed to connect. Set $SecuredPassword to the app registration secret token. $ApplicationId = "FC5775A1-0970-4718-8011-4847FEF89666" $SecuredPassword = "<set your secret here>" $tenantID = "A94B9837-0093-4CCF-AE2A-0A0F4EDC9593" # Convert the secret to a secure string. $SecuredPasswordPassword = ConvertTo-SecureString -String $SecuredPassword -AsPlainText -Force # Convert all parameters in a PSCredential object. $ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationId, $SecuredPasswordPassword # Connect to Microsoft Graph using this credential. Connect-MgGraph -TenantId $tenantID -ClientSecretCredential $ClientSecretCredential # Attempt to list mailboxes from a mailbox we don't have access to. This should fail. Get-MgUserMessage -UserId "inaccessible@domain.com" -Property "sender,subject" # Attempt to list mailboxes from a mailbox we do have access to. This should succeed. Get-MgUserMessage -UserId "accessible@domain.com" -Property "sender,subject"