Skip to content

Instantly share code, notes, and snippets.

@sunnyc7
Forked from jstangroome/ConvertFrom-IISW3CLog.ps1
Created January 25, 2014 14:51
Show Gist options
  • Save sunnyc7/8617526 to your computer and use it in GitHub Desktop.
Save sunnyc7/8617526 to your computer and use it in GitHub Desktop.
function ConvertFrom-IISW3CLog {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Alias('PSPath')]
[string[]]
$Path
)
process {
foreach ($SinglePath in $Path) {
$FieldNames = $null
$Properties = @{}
Get-Content -Path $SinglePath |
ForEach-Object {
if ($_ -match '^#') {
#metadata
if ($_ -match '^#(?<k>[^:]+):\s*(?<v>.*)$') {
#key value pair
if ($Matches.k -eq 'Fields') {
$FieldNames = @(-split $Matches.v)
}
}
} else {
$FieldValues = @(-split $_)
$Properties.Clear()
for ($Index = 0; $Index -lt $FieldValues.Length; $Index++) {
$Properties[$FieldNames[$Index]] = $FieldValues[$Index]
}
[pscustomobject]$Properties
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment