-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1096.ps1
More file actions
29 lines (24 loc) · 926 Bytes
/
Copy path1096.ps1
File metadata and controls
29 lines (24 loc) · 926 Bytes
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
<#
.Synopsis
Searches text files by pattern and displays the results.
.Description
Searches text files by pattern and displays the results.
.Notes
Based on versions from http://weblogs.asp.net/whaggard/archive/2007/03/23/powershell-script-to-find-strings-and-highlight-them-in-the-output.aspx and from http://poshcode.org/426
Makes use of Out-ColorMatchInfo found at http://poshcode.org/1095.
#>
#requires -version 2
param (
[Parameter(Mandatory=$true)]
[regex] $pattern,
[string] $filter = "*.*",
[switch] $recurse = $true,
[switch] $caseSensitive = $false,
[int[]] $context = 0
)
if ((-not $caseSensitive) -and (-not $pattern.Options -match "IgnoreCase")) {
$pattern = New-Object regex $pattern.ToString(),@($pattern.Options,"IgnoreCase")
}
Get-ChildItem -recurse:$recurse -filter:$filter |
Select-String -caseSensitive:$caseSensitive -pattern:$pattern -AllMatches -context $context |
Out-ColorMatchInfo