颜色编码获取内容结果 [英] Colour-coding get-content results
本文介绍了颜色编码获取内容结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 powershell 脚本,可以监控日志文件,过滤掉有趣的部分,然后在将这些部分写入文件时将它们呈现给我.效果很好.感兴趣的线是:
I've got a powershell script that monitors a log file, filters out the interesting bits and then presents those bits to me as and when they are written to the file. Works wonderfully. The line of interest is:
get-content "$logFile" -wait | where { select-string $searchTerm -inp $_ }
现在我想变得漂亮!
我希望每次遇到特定术语时字体颜色都会改变.我可以很容易地设置字体颜色,但是您将如何使用上述语句即时进行设置?
I would like the font colour to change everytime a particular term is encountered. I can set the font colour easily enough, but how would you do it on-the-fly with the above statement?
想通了,但 8 小时内无法发布答案.明天上传.
Figured it out, but can't post an answer for 8 hours. Will upload it tomorrow.
推荐答案
尝试
Get-Content $logFile -Wait |
Select-String $searchTerm |
ForEach {write-host -ForegroundColor red $_.line}
这篇关于颜色编码获取内容结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文