I have a script that will send an email of the cluster status, but the output in the email body is off. How can I correct this to have it line up correctly or have it in a nice table format with borders?

$cluster = Get-ClusterGroup | Out-file c:\test.txt

$body = [System.IO.File]::ReadAllText(“c:\test.txt”)

$MailMessage = @{
To = “blahblah@blah.com
From = “blahblah@blah.com
Subject = “SQL Cluster Status”
Body = “$body”
Smtpserver = ‘blah.blah.local’
ErrorAction = “SilentlyContinue”
}
Send-MailMessage @MailMessage

In the Email body it looks like this:

Name OwnerNode State


Available Storage NODE3 Online

Cluster Group NODE4 Online

INST01 NODE1 Online

INST02 NODE2 Online

INST03 NODE3 Online

INST04 NODE1 Online

8 Spice ups

If you post code, please use the ‘Insert Code’ button. Please and thank you!

192033ab-bb8f-4032-88a5-8e2313af0344-codebutton_small.png

convert it to a HTML table and send it as HTML body.

zero percent tested but that’s the idea

$cluster = Get-ClusterGroup | Out-file c:\test.txt

$body = [System.IO.File]::ReadAllText("c:\test.txt")

$MailMessage = @{
    To          = "blahblah@blah.com"
    From        = "blahblah@blah.com"
    Subject     = "SQL Cluster Status"
    Body        = $body | ConvertTo-Html | Out-String
    BodyAsHTML  = $true
    Smtpserver  = 'blah.blah.local'
    ErrorAction = "SilentlyContinue"
}

Send-MailMessage @MailMessage
1 Spice up

You’ll need to format your object as HTML and not text.

$HTML = Get-ClusterGroup | ConvertTo-Html

If you want to make it pretty that can be a bit more complicated. I recommend using PS2HTMLTable with a shameless plug.

Just make sure when you send your email you add the -BodyAsHtml parameter

1 Spice up

Sweet, after importing the PS2HTML module I got it in a format I was looking for. Thanks!

1 Spice up