VMware Cloud Community
DZ1
Hot Shot
Hot Shot

Bold text in output

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 {

$vDataStore = New-Object PSObject
$vDataStore | Add-Member -MemberType NoteProperty -Name "vCenter Datastores" -Value ($Alldatastore).count
$vDataStore | Add-Member -MemberType NoteProperty -Name "Total storage capacity of datastores" -Value ("$([Math]::Round((($Alldatastore | measure -Property CapacityGB -sum).sum) / 1024))" + "(TB)")
$vDataStore | Add-Member -MemberType NoteProperty -Name "Total amount of free space on datastores" -Value ("$([Math]::Round((($Alldatastore | measure -Property FreeSpaceGB -sum).sum) / 1024))" + "(TB)")

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)

0 Kudos
4 Replies
Grzesiekk
Expert
Expert

Function My-Test {

$vDataStore = New-Object PSObject
$vDataStore | Add-Member -MemberType NoteProperty -Name "vCenter Datastores" -Value ($Alldatastore).count
$vDataStore  | Add-Member -MemberType NoteProperty -Name "Total storage capacity of  datastores" -Value ("$([Math]::Round((($Alldatastore | measure -Property  CapacityGB -sum).sum) / 1024))" + "(TB)")
$vDataStore  | Add-Member -MemberType NoteProperty -Name "Total amount of free space  on datastores" -Value ("$([Math]::Round((($Alldatastore | measure  -Property FreeSpaceGB -sum).sum) / 1024))" + "(TB)")

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

--- @blog https://grzegorzkulikowski.info
0 Kudos
DZ1
Hot Shot
Hot Shot

Thanks, that's the way I thought it would work, but the output has the tags included. 

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
DZ1
Hot Shot
Hot Shot

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. 

0 Kudos