Create Mailbox General Report
Introduction
This script will create a report in CSV for Mailboxes Detail.
Scenarios
This script is to help Exchange Admins to create a report for Mailboxes via PowerShell.
Script
This script contains one advanced function New-OSCGeneralMailboxReport, you can use this script in the following ways:
Step1: Run the script in the Exchange Management Shell, type the one command: Import-Module <Script Path> at the prompt.
For example, type Import-Module C:\Script\NewGeneralMailboxReport.psm1
Here are some code snippets for your references.
$CheckServer = Get-MailboxServer $Server -ErrorAction SilentlyContinue
$CheckDB = Get-MailboxDatabase $Database -ErrorAction SilentlyContinue
if($CheckServer -and $CheckDB){
#Check DB inside Server
$CheckServerName = $CheckDB.Server.Name
if($CheckServerName -eq $Server){
Get-Mailbox -Database $Database -ResultSize Unlimited | Get-MailboxStatistics | Select @{Name='Name'; Expression={((Get-Mailbox $_.displayname).Name)}},DisplayName,ServerName,DataBase,ItemCount,@{Name='OU'; Expression={((Get-Mailbox $_.displayname).OrganizationalUnit)}},@{Name='PrimarySMTPAddress'; Expression={((Get-Mailbox $_.displayname).PrimarySMTPAddress)}},TotalItemSize | Export-Csv $CSVPath | Out-Null
}
Else{
Write-Host "Database $Database is not in Server $Server ."
}
}
Else{
Write-Host "Database Name $Database or Server Name $Server is not correct."
}
$CheckServer = Get-MailboxServer $Server -ErrorAction SilentlyContinue
$CheckDB = Get-MailboxDatabase $Database -ErrorAction SilentlyContinue
if($CheckServer -and $CheckDB){
#Check DB inside Server
$CheckServerName = $CheckDB.Server.Name
if($CheckServerName -eq $Server){
Get-Mailbox -Database $Database -ResultSize Unlimited | Get-MailboxStatistics | Select @{Name='Name'; Expression={((Get-Mailbox $_.displayname).Name)}},DisplayName,ServerName,DataBase,ItemCount,@{Name='OU'; Expression={((Get-Mailbox $_.displayname).OrganizationalUnit)}},@{Name='PrimarySMTPAddress'; Expression={((Get-Mailbox $_.displayname).PrimarySMTPAddress)}},TotalItemSize | Export-Csv $CSVPath | Out-Null
}
Else{
Write-Host "Database $Database is not in Server $Server ."
}
}
Else{
Write-Host "Database Name $Database or Server Name $Server is not correct."
}
Example 1: Create a General Mailbox Report for all Mailboxes in Exchange Server.
Command: New-OSCGeneralMailboxReport -CSVPath "C:\Report.csv"
Screenshot:
Example 2: Create a General Mailbox Report for all Mailboxes in Exchange Mailbox Server Server1.
Command: New-OSCGeneralMailboxReport -CSVPath "C:\Report.csv" -Server "Server1"
Screenshot:
Example 3: Create a General Mailbox Report for all Mailboxes in Exchange Mailbox Database DB1.
Command: New-OSCGeneralMailboxReport -CSVPath "C:\Report.csv" -Database "DB1"
Screenshot:
Prerequisite
Exchange 2010 and above Exchange Version
English Version only
PowerShell 2.0
Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.