Skip to content

Instantly share code, notes, and snippets.

@realslacker
Created August 28, 2024 18:46
Show Gist options
  • Save realslacker/fca03cce6251134c12830d4f2bb68147 to your computer and use it in GitHub Desktop.
Save realslacker/fca03cce6251134c12830d4f2bb68147 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Highlights output from a previous command
#>
[CmdletBinding()]
param(
[Parameter( Mandatory, ValueFromPipeline )]
[string[]]
$InputObject,
[string[]]
$String,
[string[]]
$Match,
[string[]]
$Like,
[ConsoleColor]
$HighlightForeground = 'Cyan',
[ConsoleColor]
$HighlightBackground,
[ConsoleColor]
$LowlightForeground = 'DarkGray',
[ConsoleColor]
$LowlightBackground,
[switch]
$Bell
)
begin {
$String = $String | ForEach-Object { "*$($_.Trim('*'))*" }
$Like += $String
$HighlightSplat = @{}
if ( $HighlightForeground ) { $HighlightSplat.ForegroundColor = $HighlightForeground }
if ( $HighlightBackground ) { $HighlightSplat.BackgroundColor = $HighlightBackground }
$LowlightSplat = @{}
if ( $LowlightForeground ) { $LowlightSplat.ForegroundColor = $LowlightForeground }
if ( $LowlightBackground ) { $LowlightSplat.BackgroundColor = $LowlightBackground }
}
process {
$InputObject.Split("`n").Trim("`r") | ForEach-Object {
$Line = $_
if ( ( $Like | Where-Object { $Line -like $_ } ) -or ( $Match | Where-Object { $Line -match $_ } ) ) {
Write-Host $_ @HighlightSplat -NoNewline
Write-Host ('',"`a")[$Bell.IsPresent]
} else {
Write-Host $_ @LowlightSplat -NoNewline
Write-Host ''
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment