Created
September 27, 2014 02:11
-
-
Save pipin68k/198dba3afd0e1423882d to your computer and use it in GitHub Desktop.
IIS7 Log Parser for PowerShell
This file contains 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
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