I have a script that I am almost finished with, but I want to know if there is a way to bold some text when I output the results. What I do now is create some objects, and then at the end, I use write-output to write some plain text, and to write the object information. At the very end, I send an email with the results and I pipe that to out-string. I thought of convertTo-HTML, but I can't figure out how to only bold certain parts. I have the script divided into sections: so VM information, Host information, etc. I just want a nice bold title for each section. Thanks for any help.
just a sample, not the entire script
Function My-Test {
Write "This is a test", #I want the "This is a test" in bold
$vDatastore | fl
}
Send-MailMessage -SmtpServer '' -From "<..com>" -To "<.@.com>" -Subject "Test" -body (My-Test | Out-String)
Function My-Test {
Write "<b>This is a test</b>", #I want the "This is a test" in bold
$vDatastore | fl
}
Send-MailMessage -SmtpServer '' -From "<..com>" -To "<.@.com>" -Subject "Test" -body (My-Test | Out-String)
I think that should work with html tags <b> </b> for mark / unmark bold
Thanks, that's the way I thought it would work, but the output has the tags included.
If you don't set the mail body as HTML, the HTML tags will not work.
You can still produce bold text in a 'plain' email, just put an asterisk at the start and end of the text you want in bold.
The drawback is that the asterisks will be displayed as well I'm afraid
$text = "This is *bold* text"
Send-MailMessage -SmtpServer '' -From "<..com>" -To "<.@.com>" -Subject "Test" -body $text
This works with Outlook, not sure if it will work with other mail clients
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Well, I feel good in a way, I had tried these solutions, I just thought I was missing something. Unfortunately, I can't use -BodyAsHtml, because it would throw off my entire script formatting, and it's almost complete. I do use HTML for a snapshot report, so after this is done, I will revisit the script, and look at adding HTML to it, for now, I just want this thing over with.
Thanks for the help.