Skip to content

Export Office 365 mailbox permissions to CSV

We want to get a list of Office 365 mailbox permissions because we like to know which user has access to which mailbox. The mailbox permissions are full access, send as, and send on behalf. Signing in to the Microsoft 365 admin portal and going through the users one by one to find the mailbox permissions takes a lot of time. An excellent way to export an Office 365 mailbox permissions report is with PowerShell. In this article, we will look at how to export Office 365 mailbox permissions to CSV with PowerShell.

Introduction

The script will go through all the users and shared mailboxes in Microsoft 365/Office 365 and export the mailbox permissions:

  • Full Access
  • Send As
  • Send on Behalf

Note: Do you want to export Exchange on-premises mailbox permissions? Read the article Export mailbox permissions to CSV file.

Connect to Exchange Online

Before we can proceed further and export Office 365 mailbox permissions to CSV, we need to install and connect to Exchange Online PowerShell.

Start Windows PowerShell as administrator and run the cmdlet Connect-ExchangeOnline.

PS C:\> Connect-ExchangeOnline

Now that we are connected, we can go to the next step.

Prepare Get-MailboxPermissions PowerShell script

Create two folders on the C:\ drive:

  • Temp
  • Scripts

Download the Get-MailboxPermissions.ps1 PowerShell script and place it in C:\scripts folder. The script will export the CSV file to the C:\temp folder.

Export Office 365 mailbox permissions to CSV scripts folder

Run Get-MailboxPermissions PowerShell script

Get Office 365 mailbox permissions with PowerShell. First, change the path to the scripts folder. After that, run the script Get-MailboxPermissions.ps1.

PS C:\> cd c:\scripts\
PS C:\scripts> .\Get-MailboxPermissions.ps1

Open Office 365 mailbox permissions report CSV file

The Get-MailboxPermissions.ps1 PowerShell script will export Office 365 mailbox permissions to CSV file. Find the file MailboxPermissions.csv in the path C:\temp.

Export Office 365 mailbox permissions to CSV temp folder

Open the CSV file with your favorite application. In our example, it’s Microsoft Excel.

Export Office 365 mailbox permissions to CSV file

The Office 365 mailbox permissions report looks excellent.

Out-GridView

Suppose you want to see the report in the grid view window. For example, you like to know how the report looks before you export it to CSV. If so, we can use the Out-GridView cmdlet.

Change line 59 from:

$Report | Sort -Property @{Expression = { $_.MailboxType }; Ascending = $False }, Mailbox | Export-Csv "c:\temp\MailboxPermissions.csv" -NoTypeInformation -Encoding UTF8

to:

$Report | Sort -Property @{Expression = { $_.MailboxType }; Ascending = $False }, Mailbox | Out-GridView

After changing the above line, let’s run the script to check its appearance in the grid view window.

Export Office 365 mailbox permissions to CSV Out-GridView

The Office 365 mailbox permissions in the out grid view window look great.

Did this help you to export Office 365 mailbox permissions to CSV file?

Read more: Set default calendar permissions for all users with PowerShell »

Conclusion

You learned how to export Office 365 mailbox permissions with PowerShell. Get the Office 365 mailbox permissions report with Get-MailboxPermissions PowerShell script and have a close look through it. After reviewing, adjust the mailbox permissions to your needs.

Did you enjoy this article? You may also like Manage calendar permissions in Office 365 with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 11 Comments

  1. Hello Ali,

    thanks for your work!
    I was facing issues with special characters in “Display Name”, e.g. Jérôme.

    > Get-ExoRecipient : Error while querying REST service. HttpStatusCode=400 ErrorMessage=Microsoft.OData.ODataException: Bad Request – Error in query syntax.

    In case someone else is struggling too, here is my dirty fix:

    # Check if this mailbox has granted Send on Behalf of permission to anyone
    If (![string]::IsNullOrEmpty($M.GrantSendOnBehalfTo)) {
    ForEach ($Permission in $M.GrantSendOnBehalfTo) {
    $helpmbx = (Get-Mailbox $Permission).Alias #add
    $ReportLine = [PSCustomObject] @{
    Mailbox = $M.DisplayName
    UPN = $M.UserPrincipalName
    Permission = “Send on Behalf Of”
    AssignedTo = (Get-ExoRecipient -Identity $helpmbx).PrimarySmtpAddress #edit
    MailboxType = $M.RecipientTypeDetails
    }
    $Report.Add($ReportLine)
    }
    }

    Regards
    Phips

    1. I just ran the script, and I couldn’t reproduce this. The script works with special characters in “Display Name” without errors.

      But if anyone else is getting this error, it will help them.

      Thanks for sharing the fix, Phips.

  2. Helped me track down some permissions issues on a tenant with 1500+ mailboxes. MUCH APPRECIATED!!!

  3. Thank for this amazing script… was facing the challenge of sorting out 300+ mailboxes and their respective trustee access… this made short work of it.

  4. Is there a way to export for just one user? We have over 500 users and this will take forever!

  5. Thank you very much for this script! This script gives a complete overview about all given rights in Exchange.

  6. Thanks for the script.
    We have several domains in our tenant. is it possible to read only a specific domain for the permissions?

    for example exportScript.ps1 -domainName company123.com

    best regards

    1. Hi,
      have already solved it as follows,

      in the script in the second line

      -Filter {EmailAddresses -like “*Domain.com*”}

      I only get the following error, even without my adjustment of the filter

      Get-ExoRecipient : Error while querying REST service. HttpStatusCode=500 ErrorMessage=Microsoft.OData.ODataException: Bad Request – Error in query
      syntax.
      at Microsoft.OData.UriParser.ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression(String segmentText, String& identifier, String&
      parenthesisExpression)

      I got the CSV exported despite this, but the error always occurs.

      But the scripts works.

      Jannis

Leave a Reply

Your email address will not be published. Required fields are marked *