Skip to content
Menu

Who Can Access Which Mailbox

One row per grant of Full Access, Send As or Send on Behalf held by someone other than the owner. Groups show as groups, and unresolved leftovers show as a SID.

Who can access which mailbox is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Who can access which mailbox. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: Organization.Read.All; ExchangeOnlineManagement 3.1+, Exchange.ManageAsApp, read role
Read-onlyReads, changes nothing

What It Does

The script is read-only. It connects to Exchange Online as your app, lists the mailboxes (all of the chosen type, or the one in TargetMailbox) and collects three kinds of access that someone other than the owner holds on each one.

Full Access counts only permissions assigned directly to the mailbox, not inherited, not denied and not the owner's own entry. Send As counts the allowed entries other than the owner's. Send on Behalf is the mailbox's list of people who can send on its behalf.

Each grant is one row: mailbox, mailbox type, permission and trustee. When access is given to a group, the group is the trustee and its members are not expanded. Folder and calendar permissions are not included. A trustee that no longer resolves shows as a SID, which is usually a leftover worth removing.

It makes two permission calls per mailbox, so a tenant with thousands of mailboxes takes a while and Exchange may slow it down. If a mailbox read fails, the script warns and moves on. Use MailboxType or TargetMailbox to narrow the report. If the ExchangeOnlineManagement module is not installed, the run is skipped.

To add or remove one grant, use set-mailbox-permission.

Before You Run It

  • Register an app for this client with a certificate, and keep the certificate with its private key on the computer that runs the script.
  • Give the app the Microsoft Graph application permission Organization.Read.All and the Exchange.ManageAsApp permission.
  • Assign the app an Exchange read role, for example Global Reader.
  • Install the ExchangeOnlineManagement module (version 3.1 or later) on the computer.
  • On a large tenant, start with MailboxType=Shared or a TargetMailbox, then widen.
  • Export with ExportPath if you want to review the rows in a spreadsheet.

Type and Risk

  • Type: Report. It collects facts into a table and never alerts. It exits 0, or 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: 1 to 30 minutes depending on the number of mailboxes.
  • Example answer: "14 mailbox access grant(s) on 9 of 120 mailbox(es): FullAccess 8, SendAs 4, SendOnBehalf 2"
  • Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • TenantId: The client's tenant ID (a GUID) or domain such as contoso.onmicrosoft.com. Required.
  • ClientId: The app registration's Application (client) ID, a GUID. Required.
  • CertificateThumbprint: Thumbprint of the app's certificate, with its private key in LocalMachine\My or CurrentUser\My on this computer. Preferred. Leave empty to use the ClientSecret environment variable.
  • TargetMailbox: One mailbox (its address or UPN). Default empty: every mailbox of the chosen MailboxType.
  • MailboxType: All (default: user, shared, room and equipment mailboxes), User, Shared or Resource (room and equipment). Ignored when TargetMailbox is set.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

get-mailbox-permissions.ps1 · 1036 lines · 57.5 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.