Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save joe-scalise/d059e0323eaf84b0d8d17762b6556103 to your computer and use it in GitHub Desktop.
Use PowerShell to Parse IIS Logs for String
$logPath = "C:\inetpub\logs\LogFiles\W3SVC1\"
$logFiles = [System.IO.Directory]::GetFiles($logPath, "*.log")
# $logs will store each line of the log files in an array
$logs = @()
# Skip the comment lines
$logFiles | % { Get-Content $_ | where {$_ -notLike "#[D,F,S,V]*" } | % { $logs += $_ } }
# Example search for HTTP 500
$logs | Select-String -Pattern '500'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment