Skip to content

Instantly share code, notes, and snippets.

@pipin68k
Created September 27, 2014 02:11
Show Gist options
  • Save pipin68k/198dba3afd0e1423882d to your computer and use it in GitHub Desktop.
Save pipin68k/198dba3afd0e1423882d to your computer and use it in GitHub Desktop.
IIS7 Log Parser for PowerShell
function Read-IIS7Log
{
param(
[Parameter(Mandatory=$true)]
[string]
$Path
)
Get-Content -Path $Path |
?{$_.ToString().StartsWith("#") -eq $false }|
% {
if ($_ -notmatch "^(?<date>.*?) (?<time>.*?) (?<s_ip>.*?) (?<cs_method>.*?) (?<cs_uri_stem>.*?) (?<cs_uri_query>.*?) (?<s_port>.*?) (?<cs_username>.*?) (?<c_ip>.*?) (?<useragent>.*?) (?<sc_status>.*?) (?<sc_substatus>.*?) (?<sc_win32_status>.*?) (?<time_taken>.*?)$") {
throw "Invalid line: $_"
}
$entry = $matches
$entry.DateTime = (Get-Date ($entry.date + " " + $entry.time)).AddHours(+9)
New-Object PSObject -Property $entry
}
}
Export-ModuleMember -Function Read-IIS7Log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment