Scenario: You have to find a specific string of text in multiple files. We are going to search for the term “steve” against all RPC Client Access logs for today.
Script:
#Variables
$files = get-childitem -path “\ExSrv1c$Program FilesMicrosoftExchange ServerV15LoggingRPC Client Access”
$result = @()
$term = “steve”
#Perform the Search
$files | Where CreationTime -gt 9/6/2018| Sort CreationTime -Descending | %{
$F = $_.fullname
$result += select-string $f -pattern $term | %{$_.Line}
}
#Export Results
$result | out-file C:tempresults.txt