?
Solved

Report for Exchange not getting desired results

Posted on 2014-02-15
4
Medium Priority
?
240 Views
Last Modified: 2014-04-01
Hi all,

I'm trying to compose a mailbox size report for Exchange 2010. The output is to an html file that is automatically emailed to whoever I wish it to be. The functionality works GREAT, but the report is outputting no data. Can someone tell me why? I have multiple databases, but it still shouldn't output a file with NO data. Here is the script:

#Variables to configure
$MailServer = "my mail server"
$ReportSender = "my email"
$ReportRecipient = "their email"
$MailSubject = ("Mailbox Report for " + $MailServer + " - " + ( get-date ).ToString('yyyy/MM/dd'))

#SendEmailFunction
Function sendEmail
{ param($smtphost,$htmlFileName)
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $ReportSender, $ReportRecipient, $MailSubject, (Get-Content $htmlFileName)
$msg.isBodyhtml = $true
$smtp.send($msg)
}

$exdata = Get-MailboxStatistics -Server $MailServer | Sort-Object TotalItemSize -descending | Select-Object DisplayName, ItemCount, TotalItemSize, StorageLimitStatus

$fileName = "exchange2010Report.html"
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>"

# TABLE start
Add-Content $fileName "<table width='100%'>"

# TABLE Header
Add-Content $fileName "<tr bgcolor='#7C7C7C'>"
Add-Content $fileName "<td width='35%'>DisplayName</td>"
Add-Content $fileName "<td width='10%'>ItemCount</td>"
Add-Content $fileName "<td width='10%'>TotalItemSize</td>"
Add-Content $fileName "<td width='25%'>Database</td>"
Add-Content $fileName "<td width='20%'>StorageLimitStatus</td>"
Add-Content $fileName "</tr>"

$alternateTableRowBackground = 0

# TABLE Content
while($alternateTableRowBackground -le $exdata.length)
{
if(($alternateTableRowBackground % 2) -eq 0)
{
Add-Content $fileName "<tr bgcolor='#CCCCCC'>"
}
else
{
Add-Content $fileName "<tr bgcolor='#FCFCFC'>"
}
Add-Content $fileName ("<td width='30%'>" + $exdata[$alternateTableRowBackground].DisplayName + "</td>")
Add-Content $fileName ("<td width='10%'>" + $exdata[$alternateTableRowBackground].ItemCount + "</td>")
Add-Content $fileName ("<td width='15%'>" + $exdata[$alternateTableRowBackground].TotalItemSize + "</td>")
Add-Content $fileName ("<td width='25%'>" + $exdata[$alternateTableRowBackground].Database + "</td>")
#BelowLimit or NoChecking
if(($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "BelowLimit") -or ($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "NoChecking"))
{
Add-Content $fileName ("<td bgcolor='#007F00' width='20%'>" + $exdata[$alternateTableRowBackground].StorageLimitStatus + "</td>")
}
#IssueWarning
if($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "IssueWarning")
{
Add-Content $fileName ("<td bgcolor='#7F7F00' width='20%'>" + $exdata[$alternateTableRowBackground].StorageLimitStatus + "</td>")
}
#ProhibitSend or MailboxDisabled
if(($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "ProhibitSend") -or ($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "MailboxDisabled"))
{
Add-Content $fileName ("<td bgcolor='#7F0000' width='20%'>" + $exdata[$alternateTableRowBackground].StorageLimitStatus + "</td>")
}
Add-Content $fileName "</tr>"

$alternateTableRowBackground = $alternateTableRowBackground + 1
}
# Summe Mailboxsize
Add-Content $fileName "<tr bgcolor='#7C7C7C'>"
Add-Content $fileName ("<td width='30%'></td>")
$tempdata = MailboxStatistics -Server $MailServer | %{$_.ItemCount} | Measure-Object -Sum
Add-Content $fileName ("<td width='10%'>" + ($tempdata | Select-Object -expand Sum) + "</td>")
$tempdata = MailboxStatistics -Server $MailServer | %{$_.TotalItemSize.Value.ToMB()} | Measure-Object -Sum
Add-Content $fileName ("<td width='15%'>" + ($tempdata | Select-Object -expand Sum) + " MB</td>")
Add-Content $fileName ("<td width='25%'></td>")
Add-Content $fileName ("<td width='20%'></td>")


#TABLE end
Add-Content $fileName "</table>"

# HEAD end
Add-Content $fileName "</body>"

# HTML end
Add-Content $fileName "</html>"

sendEmail $MailServer $fileName


Any help is appreciated. Thanks!
0
Comment
Question by:roycbene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Kane - TechSoEasy earned 2000 total points
ID: 39864373
My suggestion would be to take a script we know works on other environments and see if you can get it to run on yours.

So, will this one run in your environment?
http://gallery.technet.microsoft.com/office/Exchange-2010-Top-Mailbox-b9b3b293

If so, then I would do a side-by-side comparison to see where you may have missed something.

Jeff
0
 
LVL 4

Expert Comment

by:michaelalphi
ID: 39869568
You can download complete script from here :http://gallery.technet.microsoft.com/office/Exchange-2010-Mailbox-Size-c3746baf
If you still do not find output data by using this, you can have a look at this automated option (http://www.exchangereports.net/) which would be proficient and appropriate solution for you. By using this, you will be facilitated by automatic process of emailing reports to you at a scheduled time with up to the granular level reports.
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 39871476
Isn't that pretty much what I suggested???
0
 
LVL 3

Author Comment

by:roycbene
ID: 39969645
Yes, Jeffrey. Which is why you got the points. :) Thank you, sir.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question