Functions/grep.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
filter grep { <# .SYNOPSIS A simple text filter to search for a string .DESCRIPTION A simple text filter to search for a string .PARAMETER Keyword The string searching for .EXAMPLE 'Hello','There' | grep 'Hello' Would return Hello .OUTPUTS [string] .LINK about_Functions #> #region Parameter [CmdletBinding(ConfirmImpact='None')] [OutputType('string')] Param( [Parameter(Mandatory = $False, ValueFromPipeline)] [string[]] $String, [Parameter(Mandatory = $False, ValueFromPipeline = $False)] [string] $Keyword ) #endregion Parameter begin { Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]" Write-Verbose -Message "String to search for is [$Keyword]" $Line = 0 $Count = 0 } process { foreach ($s in $String) { $Line ++ $Count ++ Write-Verbose -Message "Line $Line is [$($s)]" if ($s) { $s | Where-Object { $_ -match $keyword } } } } End { if (-not $Count) { Write-Verbose -Message 'No input' } Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]" } } |