I am used to grep under Linux a lot. So I was trying to device a way to search a bunch of files for a particular string. So I ended up writing the following bit of code as PowerShell function
function Search-PathString {
[cmdletbinding()]
param (
[Parameter(
Mandatory = $True,
ValueFromPipeline = $True)]
$SearchPath,
[Parameter(
Mandatory =$True,
ValueFromPipeline = $False)]
[string] $SearchString
)
<#
.SYNOPSIS
Search a Path recursive for the existence of a search string in all matching files and dump it to a text file.
.DESCRIPTION
Search a Path recursive for the existence of a search string in all matching files and dump it to a text file.
.EXAMPLE
Search-PathString -SearchPath "*.log" -SearchString ""
#>
Process {
Get-ChildItem $SearchPath -Recurse | Select-String -Pattern $SearchString | Out-File "$SearchString.txt"
}
}
Enjoy the code and let me know if you have ways to make it smarter.
Reacties
Op dit artikel kan niet gereageerd worden.