A report that is often asked for by anybody interested in the operation of the Exchange Server is one that includes a complete listing of users, last login times, mailbox size and database membership. Here is a useful script that can provide all of this in a CSV file, which is easily manipulated in Excel.

Copy/Paste the script into your Exchange server and run it via the Exchange Shell. It will give you everything you need.

Write-host ”

Mailbox Size Report
—————————-

1.Display in Exchange Management Shell
2.Export to CSV File
3.Enter the Mailbox Name with Wild Card (Export)
4.Enter the Mailbox Name with Wild Card (Display)”-ForeGround “Cyan”

#—————-
# Script
#—————-

Write-Host ” ”

$number = Read-Host “Choose The Task”
$output = @()
switch ($number)
{

1 {

$AllMailbox = Get-mailbox -resultsize unlimited

Foreach($Mbx in $AllMailbox)

{

$Stats = Get-mailboxStatistics -Identity $Mbx.distinguishedname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name “Display Name” -Value $mbx.displayname
$userObj | Add-Member NoteProperty -Name “Primary SMTP address” -Value $mbx.PrimarySmtpAddress
$userObj | Add-Member NoteProperty -Name “TotalItemSize” -Value $Stats.TotalItemSize
$userObj | Add-Member NoteProperty -Name “ItemCount” -Value $Stats.ItemCount

Write-Output $Userobj

}

;Break}

2 {

$CSVfile = Read-Host “Enter the Path of CSV file (Eg. C:\Report.csv)”

$AllMailbox = Get-mailbox -resultsize unlimited

$mbxcount = $AllMailbox.count
$mbxprocess = 1

Foreach($Mbx in $AllMailbox)

{

$Stats = Get-mailboxStatistics -Identity $Mbx.distinguishedname

Write-Progress -Activity “Report in Progress” -Status “Processing $mbxprocess of $mbxcount – $($mbx.displayname)” -percentcomplete ($mbxprocess/$mbxcount*100)

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name “Display Name” -Value $mbx.displayname
$userObj | Add-Member NoteProperty -Name “Alias” -Value $Mbx.Alias
$userObj | Add-Member NoteProperty -Name “RecipientType” -Value $Mbx.RecipientType
$userObj | Add-Member NoteProperty -Name “Recipient OU” -Value $Mbx.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name “Primary SMTP address” -Value $Mbx.PrimarySmtpAddress
$userObj | Add-Member NoteProperty -Name “User Principal Name” -Value $Mbx.UserPrincipalName
$userObj | Add-Member NoteProperty -Name “Database” -Value $Stats.Database
$userObj | Add-Member NoteProperty -Name “ServerName” -Value $Stats.ServerName
$userObj | Add-Member NoteProperty -Name “TotalItemSize” -Value $Stats.TotalItemSize
$userObj | Add-Member NoteProperty -Name “ItemCount” -Value $Stats.ItemCount
$userObj | Add-Member NoteProperty -Name “DeletedItemCount” -Value $Stats.DeletedItemCount
$userObj | Add-Member NoteProperty -Name “TotalDeletedItemSize” -Value $Stats.TotalDeletedItemSize
$userObj | Add-Member NoteProperty -Name “DatabaseProhibitSendReceiveQuota” -Value $Stats.DatabaseProhibitSendReceiveQuota
$userObj | Add-Member NoteProperty -Name “LastLogonTime” -Value $Stats.LastLogonTime

$output += $UserObj
$mbxprocess ++

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

;Break}

3 {

$CSVfile = Read-Host “Enter the Path of CSV file (Eg. C:\DG.csv)”

$MailboxName = Read-Host “Enter the Mailbox name or Range (Eg. Mailboxname , Mi*,*Mik)”

$AllMailbox = Get-mailbox $MailboxName -resultsize unlimited

Foreach($Mbx in $AllMailbox)

{

$Stats = Get-mailboxStatistics -Identity $Mbx.distinguishedname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name “Display Name” -Value $mbx.displayname
$userObj | Add-Member NoteProperty -Name “Alias” -Value $Mbx.Alias
$userObj | Add-Member NoteProperty -Name “RecipientType” -Value $Mbx.RecipientType
$userObj | Add-Member NoteProperty -Name “Recipient OU” -Value $Mbx.OrganizationalUnit
$userObj | Add-Member NoteProperty -Name “Primary SMTP address” -Value $Mbx.PrimarySmtpAddress
$userObj | Add-Member NoteProperty -Name “User Principal Name” -Value $Mbx.UserPrincipalName
$userObj | Add-Member NoteProperty -Name “Database” -Value $Stats.Database
$userObj | Add-Member NoteProperty -Name “ServerName” -Value $Stats.ServerName
$userObj | Add-Member NoteProperty -Name “TotalItemSize” -Value $Stats.TotalItemSize
$userObj | Add-Member NoteProperty -Name “ItemCount” -Value $Stats.ItemCount
$userObj | Add-Member NoteProperty -Name “DeletedItemCount” -Value $Stats.DeletedItemCount
$userObj | Add-Member NoteProperty -Name “TotalDeletedItemSize” -Value $Stats.TotalDeletedItemSize
$userObj | Add-Member NoteProperty -Name “DatabaseProhibitSendReceiveQuota” -Value $Stats.DatabaseProhibitSendReceiveQuota
$userObj | Add-Member NoteProperty -Name “LastLogonTime” -Value $Stats.LastLogonTime

$output += $UserObj

}

$output | Export-csv -Path $CSVfile -NoTypeInformation

;Break}

4 {

$MailboxName = Read-Host “Enter the Mailbox name or Range (Eg. Mailboxname , Mi*,*Mik)”

$AllMailbox = Get-mailbox $MailboxName -resultsize unlimited

Foreach($Mbx in $AllMailbox)

{

$Stats = Get-mailboxStatistics -Identity $Mbx.distinguishedname

$userObj = New-Object PSObject

$userObj | Add-Member NoteProperty -Name “Display Name” -Value $mbx.displayname
$userObj | Add-Member NoteProperty -Name “Primary SMTP address” -Value $mbx.PrimarySmtpAddress
$userObj | Add-Member NoteProperty -Name “TotalItemSize” -Value $Stats.TotalItemSize
$userObj | Add-Member NoteProperty -Name “ItemCount” -Value $Stats.ItemCount

Write-Output $Userobj

}

;Break}

Default {Write-Host “No matches found , Enter Options 1 or 2” -ForeGround “red”}

}

Mark Rochester

Mark Rochester

Mark is currently a Technical Design Architect for Office 365, working at Dell. His projects consist of large Enterprise implementations of Exchange Online, Azure AD, OneDrive, Skype for Business/Teams.