Search code examples
powershellwindows-scriptingwrite-host

How does one output bold text in powershell?


I got a Powershell script that do some automatic procedures, I use a "Write-Host" at the end of each one of them to tell the technical user that step is finished, but I realize is kind of hard to read and keep track so, ¿Is there a way to output a bold text?

Thank you in advance.


Solution

  • Just wording...
    Seen from the 'ConvertFrom-MarkDown` cmdlet (included with PowerShell 6 and higher), bold text actually exists:
    (Using the default PowerShell color scheme)

    ('This is **Bold** text' | ConvertFrom-MarkDown -AsVt100EncodedString).VT100EncodedString
    

    enter image description here

    But this is not completely fair, as behind the scenes, it is a matter of playing with colors. Knowing that the default foregroundcolor is Gray and White is just a little brigther and therefore looks Bold.
    Meaning that the above statement is similar to:

    Write-Host 'This is ' -NoNewline; Write-Host -ForegroundColor White 'Bold ' -NoNewline; Write-Host 'Text'