-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchin.ps1
26 lines (20 loc) · 854 Bytes
/
searchin.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
$SearchString = $args[0]
$FileFilter = $args[1]
#if the search pattern is empty do not continue
#CLI then exit the script
if($SearchString -eq "" -or $args.Count -eq 0)
{
Write-Host "Search pattern must be provided."
Return
}
if($SearchString -eq "--help")
{
Write-Host "SearchIn - Powershell script to searching for strings inside files"
Write-Host "Accepts 2 Parameters"
Write-Host "--------------------------"
Write-Host "Parameter 1: String to search for. Example: request "
Write-Host "Parameter 2 (optional): File Pattern. Example: *.sql"
Return
}
#Get-ChildItem -Path .\ -Filter $FileFilter -Recurse -File | Select-String $SearchString -List | Select-Object Path, LineNumber, Line
Get-Childitem -Path .\ -Filter $FileFilter -Recurse -File | Select-String -Pattern $SearchString | Select Path,LineNumber,Line