-
-
Save disco0/f4005e3c5d89d5a9293500273ef745bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Trace-Word | |
{ | |
[Cmdletbinding()] | |
[Alias("Highlight")] | |
Param( | |
[Parameter(ValueFromPipeline=$true, Position=0)] [string[]] $content, | |
[Parameter(Position=1)] | |
[ValidateNotNull()] | |
[String[]] $words = $(throw "Provide word[s] to be highlighted!") | |
) | |
Begin | |
{ | |
$Color = @{ | |
0='Yellow' | |
1='Magenta' | |
2='Red' | |
3='Cyan' | |
4='Green' | |
5 ='Blue' | |
6 ='DarkGray' | |
7 ='Gray' | |
8 ='DarkYellow' | |
9 ='DarkMagenta' | |
10='DarkRed' | |
11='DarkCyan' | |
12='DarkGreen' | |
13='DarkBlue' | |
} | |
$ColorLookup =@{} | |
For($i=0;$i -lt $words.count ;$i++) | |
{ | |
if($i -eq 13) | |
{ | |
$j =0 | |
} | |
else | |
{ | |
$j = $i | |
} | |
$ColorLookup.Add($words[$i],$Color[$j]) | |
$j++ | |
} | |
} | |
Process | |
{ | |
$content | ForEach-Object { | |
$TotalLength = 0 | |
$_.split() | ` | |
Where-Object {-not [string]::IsNullOrWhiteSpace($_)} | ` #Filter-out whiteSpaces | |
ForEach-Object{ | |
if($TotalLength -lt ($Host.ui.RawUI.BufferSize.Width-10)) | |
{ | |
#"TotalLength : $TotalLength" | |
$Token = $_ | |
$displayed= $False | |
Foreach($Word in $Words) | |
{ | |
if($Token -like "*$Word*") | |
{ | |
$Before, $after = $Token -Split "$Word" | |
#"[$Before][$Word][$After]{$Token}`n" | |
Write-Host $Before -NoNewline ; | |
Write-Host $Word -NoNewline -Fore Black -Back $ColorLookup[$Word]; | |
Write-Host $after -NoNewline ; | |
$displayed = $true | |
#Start-Sleep -Seconds 1 | |
#break | |
} | |
} | |
If(-not $displayed) | |
{ | |
Write-Host "$Token " -NoNewline | |
} | |
else | |
{ | |
Write-Host " " -NoNewline | |
} | |
$TotalLength = $TotalLength + $Token.Length + 1 | |
} | |
else | |
{ | |
Write-Host '' #New Line | |
$TotalLength = 0 | |
} | |
#Start-Sleep -Seconds 0.5 | |
} | |
Write-Host '' #New Line | |
} | |
} | |
end | |
{ } | |
} | |
#Trace-Word -content (Get-Content iis.log) -words "IIS", 's', "exe", "10", 'system' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment