Description
Simulating the Unix grep command to browse through all the files in the current location and all the subfolders for a specific string.
Script
Function grep { # Get pattern to search in files $patt = $args[0] # Run recursive search on all files in the current location and in subfolders Get-ChildItem -File -Recurse | %{ If (Select-String -Path $_.FullName -Pattern $patt -SimpleMatch -Quiet) { Write-Host -NoNewline "$(Split-Path $_.FullName -Parent)\" Write-Host -ForegroundColor green "$(Split-Path $_.FullName -Leaf)" } } }
Example
Searching for all the files that contain the string "created"
# Unix version: grep -r "created" # PowerShell version: grep "created"

Community Questions