header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

ConvertTo-HTML = Garbage?
Last Post 16 Jun 2008 09:22 PM by FusionX86. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
FusionX86User is Offline
New Member
New Member
Posts:3

--
11 Jun 2008 11:08 PM  

Hello all,

I'm new to this site and still fairly new to powershell and have a question. I posted this over on Technet, but didn't get any feedback. Here is the basic problem. The code I hacked together below produces a list of mailboxes that don't have an email policy. It then outputs that list along with mailbox size, smtp addresses and some other random stuff. If I redirect the output to a text file, everything shows up correctly, but I want to use HTML. If I use ConvertTo-HTML like shown below the email addresses come out as "Microsoft.Exchange.Data.ProxyAddressCollection" instead of what they should. I know I'm just missing something stupid.

I know that using Format-Table along with either ConvertTo-HTML or Export-CSV can cause this type of behavior, but I'm not doing that. Any idea how to tweak the code to get all the data converted to HTML correctly?

$mbDataCollection = @()

Get-Mailbox -ResultSize Unlimited | Where { $_.EmailAddressPolicyEnabled -Ne 'True' } |
foreach-object {
$mbStats = get-mailboxstatistics $_.identity
$mbData = "" | Select Name,Alias,DatabaseName,TotalItemSize,E,EmailAddresses
$mdbArray = $_.Database.ToString().split("\")
$mbData.Name = $_.Name
$mbData.Alias = $_.Alias
$mbData.Databasename = $mdbArray[2]
$mbData.TotalItemSize = $mbStats.TotalItemSize
$mbData.EmailAddresses = $_.EmailAddresses
$mbDataCollection += $mbData
}

$mbDataCollection | ConvertTo-Html | Out-File C:\noemailpolicy.html

Invoke-Expression C:\noemailpolicy.html

 

JaykulUser is Offline
New Member
New Member
Posts:31

--
12 Jun 2008 04:41 AM  
the ProxyAddressCollection thing is the result of trying to output a type which doesn't convert to string nicely -- in this case, you're trying to export a collection -- you need to convert the array to a string before sending it to ConvertTo-Html.

My suggestion would be to improve your Select-Object usage and to manually convert the arrays using [String]::Join ... something like this (I can't test this, so I may get it wrong):

Get-Mailbox -ResultSize Unlimited | Where { $_.EmailAddressPolicyEnabled -Ne 'True' } |
foreach-object {
$mbStats = get-mailboxstatistics $_.identity
$mbData = $_ | Select Name,Alias,EmailAddresses
$mbData.TotalItemSize = $mbStats.TotalItemSize
$mbData.Databasename = [string]::join("`n", ($_.Database.ToString().split("\")))
$mbData.EmailAddresses = [string]::join("`n", ($mbData.EmailAddresses) )
$mbData
} | ConvertTo-Html | Out-File C:\noemailpolicy.html

FusionX86User is Offline
New Member
New Member
Posts:3

--
16 Jun 2008 05:58 PM  

Jaykul,

Thanks for taking time to respond. That is a good point and I understand what you're saying. I'll play with the suggestions you gave me and see if I can get it to work. I'll respond back with results. Thanks again.

FusionX86User is Offline
New Member
New Member
Posts:3

--
16 Jun 2008 09:22 PM  

Jaykul,

That code worked great. Thanks! It gave me the correct output and trimmed my code a bit at the same time.

One other question I had and forgot to mention before was that I'd like to display the "TotalItemSize" in KB instead of Byes. I've used a select statement with @{n="Size(KB)";e={$_.TotalItemSize.value.ToKB()}} to accomplish this before, but the script was much simpler than this one. I've tried several variations of this in my script here, but not really getting what I need. The following is close, but the column name doesn't match the new size units. Any suggestions?

Get-Mailbox  -ResultSize Unlimited | Where { $_.EmailAddressPolicyEnabled -Ne 'True' } |
foreach-object {
$mbStats = get-mailboxstatistics $_.identity
$mbData = $_ | Select Name, Alias, DatabaseName, TotalItemSize, EmailAddressPolicyEnabled, EmailAddresses
$mbData.TotalItemSize = $mbStats.TotalItemSize.Value.ToKB()
$mbData.Databasename = [string]::join("`n", ($_.Database.ToString().split("\")))
$mbData.EmailAddresses = [string]::join("`n", ($mbData.EmailAddresses) )
$mbData
} | ConvertTo-Html | Out-File C:\noemailpolicy.html

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer