Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change font properties in PowerShell 5?

I want to make the font as bold for the path that I'm printing using Write-Host. I'm flexible to using other methods like echo or something else.

I've tried other methods like Write-Debug, etc, also checked the module WindowsConsoleFonts. But none of them supports font properties like making them bold or italic while printing them.

$pathString = "[" + (Get-Location) + "]"
Write-Host $pathString -ForegroundColor Cyan

I'm using PowerShell 5.1 which doesn't support MarkDown rendering, else I would have done it using Markdown.

like image 886
16kp Avatar asked Oct 23 '25 16:10

16kp


1 Answers

Some built-in ANSI text formatting sequences were added in PowerShell 7.2 (PSCore). They are accessible via the $PSStyle variable/object. More documentation can be found at about_ANSI_Terminals (Microsoft link).

Try entering $PSStyle.Formatting, $PSStyle.Foreground, $PSStyle.Background (or simply $PSStyle) at a PowerShell prompt for a list of some supported styles and formatters.

Example (Bold)

Write-Host "hello $($PSStyle.bold)bold$($PSStyle.BoldOff) world"

Example (Foreground colors)

$PSStyle.Foreground
like image 59
luckman212 Avatar answered Oct 25 '25 05:10

luckman212