Created
January 6, 2020 12:37
-
-
Save joe-scalise/2a9e4ec349dba9e7319954ac48d2f936 to your computer and use it in GitHub Desktop.
Example Searching Log File w/Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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