HOST输出格式控制:颜色、字体


PowerShell交流中心分类: QuestionsHOST输出格式控制:颜色、字体
0
Full_Chaos asked 5年 ago

有没有办法对HOST输出的某些关键字进行高亮输出,即改变字体或颜色?
需求是这样的,用powershell做了一个通过串口读设备log,并提取log中关心的信息的脚本,当提取出来看某个数据在某个范围时,希望能在write-host时突出显示这个数据。

1 Answers
1
Best Answer
Liu Liu answered 5年 ago

Write-Host “Executing commands…” -Foreground “Yellow”
-ForegroundColor

Specifies the text color. There is no default. The acceptable values for this parameter are:

  • Black
  • DarkBlue
  • DarkGreen
  • DarkCyan
  • DarkRed
  • DarkMagenta
  • DarkYellow
  • Gray
  • DarkGray
  • Blue
  • Green
  • Cyan
  • Red
  • Magenta
  • Yellow
  • White
Full_Chaos replied 5年 ago

多谢回复!
其实是想问有没有类似{1,-10:##.##}这样方便的行内控制方式?逐个改前景背景色太费劲了。

苍何 replied 4年 ago

PowerShell 5.1 开始,PowerShell 控制台支持 VT 转义序列,可以参考以下链接:
http://blog.vichamp.com/2018/03/29/using-colors-in-powershell-console/