andrewducker: (Default)
[personal profile] andrewducker
Posted because there's no official way of converting IIS W3C logs to PowerShell objects, and the original script I found wasn't quite doing what I wanted.

# Define the location of log files and a temporary file
$LogFolder = "build1:\Logs\iis\W3SVC1\"
$LogFiles = ls "$logFolder\u_ex*.log" #Ensure we only get the correctly formatted log files if there's a mixture of styles

# 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 += $_ } }
# Then grab the first header line, and adjust its format for later
$LogColumns = ( $LogFiles | select -first 1 | % { Get-Content $_ | where {$_ -Like "#[F]*" } } ) `
-replace "#Fields: ", "" -replace "-","" -replace "\(","" -replace "\)",""

$newLine = "`r`n"

$tempCsv = "$($LogColumns[0])$newline$($Logs -join $newline)"

return $tempCsv | ConvertFrom-Csv -Delimiter " "
This account has disabled anonymous posting.
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

July 2025

S M T W T F S
   1 2 3 4 5
6 7 89 10 11 12
13 14 1516171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 15th, 2025 03:08 pm
Powered by Dreamwidth Studios