Skip to content

Instantly share code, notes, and snippets.

@smasterson
Created February 21, 2014 19:29
Show Gist options
  • Save smasterson/9141598 to your computer and use it in GitHub Desktop.
Save smasterson/9141598 to your computer and use it in GitHub Desktop.
function Find-Script
{
param
(
[Parameter(Mandatory=$true)]
[string]$Keyword
)
# Max results returned
$Maximum = 20
# Path to scripts directory
$StartPath = "E:\scripts"
Get-ChildItem -Path $StartPath -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue |
Select-String -SimpleMatch -Pattern $Keyword -List |
Select-Object -Property FileName, Path, Line -First $Maximum |
Out-GridView -Title 'Script Files Found'
}
$keyword = Read-Host "Enter keyword to search for"
Find-Script $keyword
# Prompt to exit script
Write-Host "`n`nPress any key to exit - also closes grid view window..." -fore "Yellow"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment