HTML output into Body of EMail

I have this script creating output in HTML as an attachment

I would like to take the attachment and place it into the body of the email.

I tried a few methods nothing see to pan out.

Here is my current script

$Server = hostname

function Set-Email { $Params = @{

 Subject = "$Server Clients By IP Address"

 Body = "Clients By IP Address open attachment"

 Attach = "$Logfolder\$htmlfile"

 From = "no-reply@mynet.com"

 To = "systems-alert@mynet.com"

 smtpserver = "InternalRelay.MYNET.COM"

}

Send-MailMessage @Params

}

$LogFolder = "c:\util\logs"

$LogFile = "clientIp.csv"

$LogParser = "C:\Program Files (x86)\Log Parser 2.2"

$htmlfile = 'ip.html'

remove-item -path $LogFolder\$LogFile -Force

remove-item -path $LogFolder\$htmlFile -Force

$Query = @"

SELECT Extract_Suffix(client-name,0,'=') as User,client-name as DN,client-software,

client-software-version as Version,client-mode,client-ip,protocol

from 'G:\Program Files\Microsoft\Exchange Server\V15\Logging\RPC Client Access\RCA*.log'

WHERE (operation='Connect') GROUP BY User,DN,client-software,Version,client-mode,client-ip,protocol

ORDER BY User" -i:CSV -nSkipLines:4 -o:CSV

"@

& $Logparser\LogParser.exe $Query | out-file $Logfolder\$LogFile

$csv1 = import-csv -path $LogFolder\$logfile

$reporthtml = $csv1 | ConvertTo-Html -Fragment

$htmlhead="<html>

<style>

BODY{font-family: Arial; font-size: 8pt;}

H1{font-size: 22px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;}

H2{font-size: 18px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;}

H3{font-size: 16px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;}

TABLE{border: 1px solid black; border-collapse: collapse; font-size: 8pt;}

TH{border: 1px solid #969595; background: #dddddd; padding: 5px; color: #000000;}

TD{border: 1px solid #969595; padding: 5px; }

td.pass{background: #B7EB83;}

td.warn{background: #FFF275;}

td.fail{background: #FF2626; color: #ffffff;}

td.info{background: #85D4FF;}

</style>

<body>

<p>Report of Exchange</p>"

$htmltail = "</body></html>"

$htmlreport = $htmlhead + $reporthtml + $htmltail

$htmlreport | Out-File $Logfolder\$htmlfile -Encoding UTF8

Set-Email

This works using attachment

I have tied this

$bigbody = get-content($LogFolder</span>$LogFile) | out-string

added this also

BodyAsHtml = $true

 

Any ideas

 

Thank you

 

Tom

 

 

 

Can’t see where the $BigBody variable is used ? you can give $htmlreport directly to -Body with -BodyAsHtml switch.

KVPRASOON,

This was how I tried.

 

$Server = hostname

function Set-Email { $Params = @{

 Subject = "$Server Clients By IP Address"

 Body = "$Bigbody"

 BodyAsHtml = $true

 Attach = "$Logfolder\$htmlfile"

 From = "no-reply@tgcsnet.com"

 To = "systems-alert@tgcsnet.com"

 smtpserver = "InternalRelay.TGCSNET.COM"

}

Send-MailMessage @Params

}

$LogFolder = "c:\util\logs"

$LogFile = "clientIp.csv"

$LogParser = "C:\Program Files (x86)\Log Parser 2.2"

$htmlfile = 'ip.html'

remove-item -path $LogFolder\$LogFile -Force

remove-item -path $LogFolder\$htmlFile -Force

$Query = @"

SELECT Extract_Suffix(client-name,0,'=') as User,client-name as DN,client-software,

client-software-version as Version,client-mode,client-ip,protocol

from 'G:\Program Files\Microsoft\Exchange Server\V15\Logging\RPC Client Access\RCA*.log'

WHERE (operation='Connect') GROUP BY User,DN,client-software,Version,client-mode,client-ip,protocol

ORDER BY User" -i:CSV -nSkipLines:4 -o:CSV

"@

& $Logparser\LogParser.exe $Query | out-file $Logfolder\$LogFile

$csv1 = import-csv -path $LogFolder\$logfile

$reporthtml = $csv1 | ConvertTo-Html -Fragment

$htmlhead="<html>

<style>

BODY{font-family: Arial; font-size: 8pt;}

H1{font-size: 22px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;}

H2{font-size: 18px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;}

H3{font-size: 16px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;}

TABLE{border: 1px solid black; border-collapse: collapse; font-size: 8pt;}

TH{border: 1px solid #969595; background: #dddddd; padding: 5px; color: #000000;}

TD{border: 1px solid #969595; padding: 5px; }

td.pass{background: #B7EB83;}

td.warn{background: #FFF275;}

td.fail{background: #FF2626; color: #ffffff;}

td.info{background: #85D4FF;}

</style>

<body>

<p>Report of Exchange</p>"

$htmltail = "</body></html>"

$htmlreport = $htmlhead + $reporthtml + $htmltail

$htmlreport | Out-File $Logfolder\$htmlfile -Encoding UTF8

$bigbody = get-content("$LogFolder\$LogFile") | out-string

Set-Email

 

I bolded the changes.

 

You say “you can give $htmlreport directly to -Body with -BodyAsHtml switch.”

How do I do that??

-BodyAsHTML $htmlreport ???

 

Thanks

 

Tom

 

 

 

 

I got it to work Thanks for leading me to the proper direction