Exchange Online Setup 

To restrict app access to specific mailboxes, you need the Exchange Online PowerShell module.

Prerequisites 

PowerShell 7.x (latest recommended) is required for best compatibility. Windows PowerShell 5.1 works but may have limitations with newer module versions.

Check your version:

$PSVersionTable.PSVersion
Copied!

Install or update to PowerShell 7:

winget install Microsoft.PowerShell
Copied!

Install the ExchangeOnlineManagement module. Run PowerShell as Administrator:

Install-Module -Name ExchangeOnlineManagement -Force -AllowClobber
Copied!

Import and connect 

Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName your-admin@yourdomain.com
Copied!

This opens a browser window for authentication. Use an account with Exchange Admin rights.

Create the Application Access Policy 

The New-ApplicationAccessPolicy cmdlet restricts your application to only access specific mailboxes instead of all mailboxes in the tenant.

Parameters:

  • -AppId: The Application (client) ID from your Microsoft Entra ID app registration
  • -PolicyScopeGroupId: The email address of the mailbox or mail-enabled security group the app is allowed to access
  • -AccessRight RestrictAccess: Limits the app to only the specified mailbox(es)
  • -Description: A human-readable description for the policy
New-ApplicationAccessPolicy -AppId "<your-app-id>" -PolicyScopeGroupId "shared@yourdomain.com" -AccessRight RestrictAccess -Description "Restrict to shared mailbox"
Copied!

To verify the policy was created:

Get-ApplicationAccessPolicy | Format-List
Copied!

To test if the policy works correctly:

Test-ApplicationAccessPolicy -Identity "shared@yourdomain.com" -AppId "<your-app-id>"
Copied!

Troubleshooting 

# Check if connected
Get-ConnectionInformation

# Verify cmdlet exists
Get-Command New-ApplicationAccessPolicy

# Check PowerShell version (needs 5.1+)
$PSVersionTable.PSVersion

# List all existing policies
Get-ApplicationAccessPolicy | Format-List

# Remove a policy if needed
Remove-ApplicationAccessPolicy -Identity "<policy-id>"
Copied!