locked
Exchange 2010 report not working RRS feed

  • Question

  • 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!

    Saturday, February 15, 2014 4:15 PM

Answers

  • Are you sure that $exdata has what you want in it?

    Maybe, after this line in your script:

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

    Add this (just to sure there's something in the list:

    Write-Host "Size of `$exdata is $($exdata.length)"

    I'd also add "Set-PSDebug -Strict" at the top of your script. Undefined variables are a lot easier to find if errors are thrown when you try to use them. Misspellings are more common than any of us would like!

    Are you getting the correct number of rows in the table but no data in the cells? Or is there only one row in the table (because $exdata is empty so the length is zero, which means you "while" loops only once).


    --- Rich Matheisen MCSE&I, Exchange MVP

    Saturday, February 15, 2014 9:49 PM

All replies

  • You can make it simple on the HTML format...Try the below format on replacement of HTML format page..

    ## HTML PAGE FORMAT

    $a = “<style>”
    $a = $a + “BODY{background-color:Lavender;}”
    $a = $a + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
    $a = $a + “TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Bisque}”
    $a = $a + “TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Beige}”
    $a = $a + “</style>”

    ## HTML PAGE FORMAT

    $exdata = Get-MailboxStatistics -Server $MailServer | Sort-Object TotalItemSize -descending | Select-Object DisplayName, ItemCount, TotalItemSize, StorageLimitStatus | ConvertTo-Html -body “<h2> Mailbox Size Users List Report</h2>” -head $a | Set-Content c:\temp\Exchange2013UserReport.html


    Exchange Queries

    Saturday, February 15, 2014 4:47 PM
  • Thanks for the reply.

    Your report didn't work either. The formatting wasn't the problem. I had no issue with the html document, nor did i have issues with the functionality (regarding output) of the report. My issue is that the $exdata is returning no data. I have all my permissions right, but I don't know why this isn't retrieving any information.

    Saturday, February 15, 2014 5:07 PM
  • Are you sure that $exdata has what you want in it?

    Maybe, after this line in your script:

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

    Add this (just to sure there's something in the list:

    Write-Host "Size of `$exdata is $($exdata.length)"

    I'd also add "Set-PSDebug -Strict" at the top of your script. Undefined variables are a lot easier to find if errors are thrown when you try to use them. Misspellings are more common than any of us would like!

    Are you getting the correct number of rows in the table but no data in the cells? Or is there only one row in the table (because $exdata is empty so the length is zero, which means you "while" loops only once).


    --- Rich Matheisen MCSE&I, Exchange MVP

    Saturday, February 15, 2014 9:49 PM