View Categories

List mailboxes in Exchange database with PowerShell

1 min read

Get mailbox database name #

Before you start, you want to have the mailbox database name. Run Exchange Management Shell as administrator.

Get all mailbox databases with the Get-MailboxDatabase cmdlet. Use the -Status switch to check the mailbox database mount status. Use the -IncludePreExchange switch to get mailbox databases in older Exchange servers.

Note: Remember to mount the mailbox database. Otherwise, you can’t list the mailboxes.

[PS] C:\>Get-MailboxDatabase -Status -IncludePreExchange | Sort Name | Format-Table Name, Server, Mounted

Name Server    Mounted
---- ------    -------
DB01 EX01-2016    True
DB02 EX02-2016    True
DB03 EX01-2016    True
DB04 EX02-2016    True

In the next step, we will list all mailboxes in the Exchange database.

List all mailboxes in a database #

Find out what mailboxes are in a mailbox database. In this example, we will check mailbox database DB02.

[PS] C:\>Get-Mailbox -Database "DB02" | ft Name, Alias, WindowsEmailAddress, UserPrincipalName

Name            Alias           WindowsEmailAddress       UserPrincipalName
----            -----           -------------------       -----------------
Piers Bower     Piers.Bower     [email protected]     [email protected]
Richard Grant   Richard.Grant   [email protected]   [email protected]
Nicholas Murray Nicholas.Murray [email protected] [email protected]
Ruth Dickens    Ruth.Dickens    [email protected]    [email protected]
Jonathan Fisher Jonathan.Fisher [email protected] [email protected]
Grace Rees      Grace.Rees      [email protected]      [email protected]
Patrick Mors    Patrick.Mors    [email protected]    [email protected]

Note The above command doesn’t show if there are archive mailboxes in the mailbox database.

Find out the archive mailboxes in a mailbox database. In this example, we will check mailbox database DB02.

[PS] C:\>Get-Mailbox | Where-Object {$_.ArchiveDatabase -like "DB02"} | ft Name, Alias, WindowsEmailAddress, UserPrincipalName

Name            Alias           WindowsEmailAddress       UserPrincipalName
----            -----           -------------------       -----------------
Hannah Duncan   Hannah.Duncan   [email protected]   [email protected]
Hasan Hamza     Hasan.Hamza     [email protected]     [email protected]
Jonathan Fisher Jonathan.Fisher [email protected] [email protected]
Max Gibson      Max.Gibson      [email protected]      [email protected]
Piers Bower     Piers.Bower     [email protected]     [email protected]
Richard Grant   Richard.Grant   [email protected]   [email protected]
Simon Berry     Simon.Berry     [email protected]     [email protected]

Export all mailboxes in database to CSV file #

Export all mailboxes to CSV file in the directory C:\temp. Create a temp folder if you don’t have one.

[PS] C:\>Get-Mailbox -Database "DB02" | select Name, Alias, WindowsEmailAddress, UserPrincipalName | Export-Csv "C:\temp\MailboxesDB02.csv" -NoTypeInformation -Encoding UTF8
[PS] C:\>Get-Mailbox | Where-Object {$_.ArchiveDatabase -like "DB02"} | select Name, Alias, WindowsEmailAddress, UserPrincipalName | Export-Csv "C:\temp\ArchiveMailboxesDB02.csv" -NoTypeInformation -Encoding UTF8

Open the CSV file with Microsoft Excel or another favorite application of your choice.