Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 917
Haroldo Payares Salgado Avatar asked Mar 06 '20 14:03

Haroldo Payares Salgado


People also ask

How do I change the output color in PowerShell?

You can specify the color of text by using the ForegroundColor parameter, and you can specify the background color by using the BackgroundColor parameter. The Separator parameter lets you specify a string to use to separate displayed objects. The particular result depends on the program that is hosting PowerShell.

How do I get full output in PowerShell?

All you have to do is to go to Out-String and add the -Width parameter. Keep in mind that the -Width parameter of Out-File cmdlet specifies the number of characters in each line of output. Any other characters will simply be truncated, not wrapped.

How do I display output in a Table Format in PowerShell?

The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display.


2 Answers

See also:

Console Virtual Terminal Sequences

Starting in PowerShell 5.1, the PowerShell console supports VT escape sequences that can be used to position and format console text. Note that this

# Enable underline
$esc = [char]27
"$esc[4mOutput is now underlined!"

# Disable underline
$esc = [char]27
"$esc[0mReset"

Or as pointed out already, with Write-Host, just switch the text color inline for contrast...

Write-Host -ForegroundColor gray 'This is not bold ' -NoNewline
Write-Host -ForegroundColor White 'This is Bold ' -NoNewline
Write-Host -ForegroundColor gray 'This is not bold'

... that is if you did not download or can't download and use external stuff.

like image 193
postanote Avatar answered Sep 20 '22 16:09

postanote


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'
like image 30
iRon Avatar answered Sep 16 '22 16:09

iRon