Introduction
Managing shared mailboxes in Microsoft 365 is a critical task for IT administrators. One common requirement is to fetch the list of all shared mailboxes along with their respective managers. In this blog post, we will walk you through a PowerShell script that does exactly that. We’ll explain every part of the script in simple, human-friendly language, provide output examples, and ensure the content is SEO-optimized for easy discovery on Google.
1. Prerequisites
Before running the script, make sure you have:
– Proper permissions to access user and mailbox data in Exchange Online.
– The Exchange Online PowerShell module installed.
– Administrator rights on your system.
2. Script Overview
This PowerShell script helps you extract details about all shared mailboxes and their respective managers. It reads from a CSV file containing shared mailbox email addresses, fetches detailed user information for each, and exports the data into another CSV file.
3. Detailed Script Explanation
# Step 1: Get user information for a single shared mailbox
Get-User -Identity "SharedMailboxEmailAddress" | Select *
# Step 2: Export all shared mailboxes with their display name, primary SMTP, and manager
Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize unlimited |
Select DisplayName, PrimarySMTPAddress, Manager |
Export-Csv -NoTypeInformation "C:\Users\Desktop\information.csv"
# Step 3: Import a list of shared mailboxes and get their detailed info
Import-CSV "C:\Users\Desktop\AllSharedMailboxesEmailAddresses.csv" |
ForEach-Object {
Get-User -Identity $_.SharedMialboxEmailAddresses |
Select DisplayName, Manager, RecipientType, RecipientTypeDetails, WindowsEmailAddress |
Export-CSV "C:\Users\Desktop\information.csv" -NoTypeInformation -Append
}
Let’s break it down step by step:
– **Step 1:** This command fetches all user properties of a specific shared mailbox.
– **Step 2:** This pulls a list of all shared mailboxes and extracts their Display Name, Primary SMTP address, and Manager, saving it into a CSV file.
– **Step 3:** This part reads from a CSV file (‘AllSharedMailboxesEmailAddresses.csv’) that contains a list of shared mailboxes. For each mailbox, it fetches detailed properties and appends them to the same output file (‘information.csv’).
**Important Note:** There is a typo in the field name ‘SharedMialboxEmailAddresses’. It should be ‘SharedMailboxEmailAddresses’.
Sample Output
The resulting CSV file (‘information.csv’) will look something like this:
DisplayName, Manager, RecipientType, RecipientTypeDetails, WindowsEmailAddress
HR Shared Mailbox, John Doe, UserMailbox, SharedMailbox, hr@domain.com
Support Team Mailbox, Jane Smith, UserMailbox, SharedMailbox, support@domain.com
Final Thoughts
By using this PowerShell script, administrators can efficiently document shared mailbox managers. This can be helpful for auditing, compliance, and general mailbox management. Always double-check your CSV input file for correct field names and ensure you have the necessary permissions before running the script.