Simple Exchange 2010 mailbox report script

I needed to quick and dirty report some mailbox sizes to a customer on Exchange 2010. I created the following script that simply does the following:

  1. List top 15 largest mailboxes in the environment
  2. List all user mailboxes in the environment
  3. List all "non" user mailboxes in the environment (rooms, equipment, etc)
Here's the powershell code:
#Variables
$fileName = "ExchangeReport.html"
$datum = Get-Date
#Start job
New-Item -ItemType file $fileName -Force
# HTML start
Add-Content $fileName "<html>"
# HEAD start
Add-Content $fileName "<head>"
add-content $fileName '<STYLE TYPE="text/css">'
add-content $fileName  "<!--"
add-content $fileName  "td {"
add-content $fileName  "font-family: Tahoma;"
add-content $fileName  "font-size: 11px;"
add-content $fileName  "border-top: 1px solid #999999;"
add-content $fileName  "border-right: 1px solid #999999;"
add-content $fileName  "border-bottom: 1px solid #999999;"
add-content $fileName  "border-left: 1px solid #999999;"
add-content $fileName  "padding-top: 0px;"
add-content $fileName  "padding-right: 0px;"
add-content $fileName  "padding-bottom: 0px;"
add-content $fileName  "padding-left: 0px;"
add-content $fileName  "}"
add-content $fileName  "body {"
add-content $fileName  "margin-left: 5px;"
add-content $fileName  "margin-top: 5px;"
add-content $fileName  "margin-right: 0px;"
add-content $fileName  "margin-bottom: 10px;"
add-content $fileName  ""
add-content $fileName  "table {"
add-content $fileName  "border: thin solid #000000;"
add-content $fileName  "}"
add-content $fileName  "-->"
add-content $fileName  "</style>"
# HEAD end
Add-Content $fileName "</head>"
# HEAD start
Add-Content $fileName "<body>"
# Basic info
Add-Content $fileName "<COLOR = Green>"
Add-Content $fileName "Exchange Report from "
Add-Content $filename $datum
Add-Content $fileName "</COLOR>"
Add-Content $filename "<HR>"
#Get top 15 mailboxes
Add-Content $fileName "Topp 15<BR>"
$a = get-mailbox -resultsize unlimited | get-mailboxstatistics  | where {$_.objectclass -eq "Mailbox"} | sort-object totalitemsize -descending | select-object @{label="User";expression={$_.DisplayName}},@{label="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Size (GB)";expression={$_.TotalItemSize.Value.ToGB()}},@{label="Items";expression={$_.ItemCount}} -first 15  | convertto-html -fragment
Add-Content $fileName $a
#All mailboxes
Add-Content $fileName "<BR>All mailboxes<BR>"
$a = get-mailbox -resultsize unlimited | get-mailboxstatistics  | where {$_.objectclass -eq "Mailbox"} | sort-object totalitemsize -descending | select-object @{label="User";expression={$_.DisplayName}},@{label="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Size (GB)";expression={$_.TotalItemSize.Value.ToGB()}},@{label="Items";expression={$_.ItemCount}}  | convertto-html -fragment
Add-Content $fileName $a
#Get all non user mailbox
Add-Content $fileName "All non user mailboxes<BR>"
$a = get-mailbox -resultsize unlimited | where {$_.RecipientTypeDetails -ne "UserMailbox"} | get-mailboxstatistics  | sort-object totalitemsize -descending | select-object @{label="User";expression={$_.DisplayName}},@{label="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Size (GB)";expression={$_.TotalItemSize.Value.ToGB()}},@{label="Items";expression={$_.ItemCount}}  | convertto-html -fragment
Add-Content $fileName $a
add-content $filename "Script by Rikard Strand, Itera Networks as, Phone: +47 48074897"
# HEAD end
Add-Content $fileName "</body>"
 # HTML end
Add-Content $fileName "</html>" 

1 comment:

Unknown said...

Good article, thanks for sharing this useful information related to create exchange 2010 mailbox report I tried the automate tool from http://www.lepide.com/exchange-reporter/ that allows to generate of exchange Reports to save time and view status of scheduled reports (success or failure). It helps to analyze mailboxes, mailbox folder, attachment size and Outlook Web access (OWA) with the help of the reports generated and filter the reports up to the granular level.