Skip to content

Instantly share code, notes, and snippets.

@joe-scalise
Created January 6, 2020 12:37
Show Gist options
  • Select an option

  • Save joe-scalise/2a9e4ec349dba9e7319954ac48d2f936 to your computer and use it in GitHub Desktop.

Select an option

Save joe-scalise/2a9e4ec349dba9e7319954ac48d2f936 to your computer and use it in GitHub Desktop.
Example Searching Log File w/Powershell
[datetime]$TodaysDate = Get-Date -format d
$LogPath = "c:\logs\"
$foundFiles = gci -Path $LogPath -Filter *.txt | where {($_.lastwritetime -lt $TodaysDate) -and ($_.lastwritetime -ge ($TodaysDate).adddays(-60))}
foreach ( $file in $foundFiles ) {
foreach($line in (Get-Content "$LogPath\$file" )) {
#write-host "testing $($line)."
if ($line -like "*joe*") {
write-host $line
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment