troubleshooting Question

Powershell for Exchange 2003

Avatar of rkeith2412
rkeith2412Flag for United States of America asked on
ExchangePowershell
8 Comments1 Solution861 ViewsLast Modified:
I have the follwoing script that works great until I try to convert it to HTML and save it to a file so I can email it.

#HTML Email Styles
$style = "<style type='text/css'>"
$style = $style + "BODY{background-color:#FFFFFF;font-family:Verdana;}"
$style = $style + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;font-size:12px;}"
$style = $style + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#D3D3D3;text-align:center }"
$style = $style + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#FFFFFF;text-align:center }"
$style = $style + "</style>"

$file = "D:\users_over_750MB.html"

$table = @{Expression={$_.MailboxDisplayName};Label="Name";width=50}, `
@{Expression={[math]::truncate($_.Size / 1KB)};Label="Size";width=25}, `
@{Expression={$_.TotalItems};Label="Total Items";width=25}

$mailboxdata = (Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer concourse -Filter "size>=768000" | sort-object -desc Size | format-table $table)
$mailboxdata | ConvertTo-HTML -head $style | Out-File "$file"

This script used to use Select-Object instead of Format-Table and the HTML conversion worked just fine.

#HTML Email Styles
$style = "<style type='text/css'>"
$style = $style + "BODY{background-color:#FFFFFF;font-family:Verdana;}"
$style = $style + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;font-size:12px;}"
$style = $style + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#D3D3D3;text-align:center }"
$style = $style + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#FFFFFF;text-align:center }"
$style = $style + "</style>"



$file = "D:\users_over_750MB.html"
$mailboxdata = (Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer concourse -Filter "size>=1048576" | sort-object -desc Size | select-object MailboxDisplayName,Size,TotalItems)
$mailboxdata | ConvertTo-HTML -head $style | Out-File "$file"

I really want this in an easy to read HTML table instead of the long string of text I get without it.
users-over-750MB.html
ASKER CERTIFIED SOLUTION
Qlemo
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros