Dec 082013
 

If we are able to export data from public folders we should be able to export data from mailboxes. What I have done is taken the same code used in the Public Folder to HTML blog but, just replaced the public folder commands with mailbox commands.

Note: To be able to use the sortable feature you will need to download the JS script form this website, http://www.kryogenix.org/code/browser/sorttable/.

I encourage changing the HTML output to reflect the needs of your environment. When you change the value you want to output you will also need to modify the code if you want to make the table sortable by numerical value instead of ascending.  For example let’s look at a line of code:

(Get-Content C:report.htm) | Foreach-Object {if($_ -like “*TotalItemSize*”){$_ -replace “Database</th><th>”, “Database</th><th>”} else{$_}} | Set-Content C:report.htm

As you can tell from the command we are searching for anything in the report.html file “Like” TotalItemSize. Once we find this we want to replace “Database</th><th>”, with Database</th><th>” to make the table TotalItemSize sort base on a numerical value. Let take a look at the HTML source.

So the search found the phrase TotalItemsize

html1

It now will delete DisplayName<th><th> and replace it with Database</th><th>

html2

Now allowing me to sort base on the actual size of the TotalItems

html3

Here is what a sample export will look like. If you have any questions please let me know.

html4

Here is the Code

Get-Date | Select-Object Date | convertTo-HTML -head $a -Title “Mailbox Information” | Out-File c:report.htm

$server = “server name”

$a= “<script src=c:tempsorttable.js type=text/javascript></script>”

$a = $a + “<style>”

$a = $a + “BODY{background-color:gray;}”

$a = $a + “TABLE.sortable thead {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:yellow}”

$a = $a + “TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}”

$a = $a + “</style>”

Get-mailboxStatistics -Server $server| Select-Object DisplayName, Database,TotalItemSize,StorageGroupName,StorageLimitStatus,LegacyDN  | convertTo-HTML -Body “<H2>Mailbox Statistics</H2>”   |  Out-File c:report.htm -append

get-mailbox -Server $server | Select-Object DistinguishedName,IsMailboxEnabled,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitReceiveQuota,UserAccountControl  | convertTo-HTML -head $a -Title “Mailbox Information” -Body “<H2>Mailbox Information</H2>” |  Out-File c:report.htm -append

(Get-Content C:report.htm) | Foreach-Object {$_ -replace “<table>”, “<table class =sortable>”} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like “*TotalItemSize*”){$_ -replace “Database</th><th>”, “Database</th><th>”} else{$_}} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like “*IssueWarningQuota*”){$_ -replace “UseDatabaseQuotaDefaults</th><th>”, “UseDatabaseQuotaDefaults</th><th>”} else{$_}} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like “*ProhibitSendQuota*”){$_ -replace “IssueWarningQuota</th><th>”, “IssueWarningQuota</th><th>”} else{$_}} | Set-Content C:report.htm

(Get-Content C:report.htm) | Foreach-Object {if($_ -like “*ProhibitReceiveQuota*”){$_ -replace “ProhibitSendQuota</th><th>”, “ProhibitSendQuota</th><th>”} else{$_}} | Set-Content C:report.htm

Happy Exchanging!!!

821 total views, 33 views today

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">