$servers = 'REJK-P-API001','REJK-P-API002','REJK-P-APP001','REJK-P-APP002','REJK-P-APP003','REJK-P-APP004'
$header = 'date time s-sitename s-computername s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken' -split ' '


#$stats = @{}

foreach($server in $servers) {

    Write-Verbose -Verbose "Server: $server"

    #$stats[$server] = @{}

    foreach($item in (Get-Item "\\$server\d-drive\logfiles\w3svc*\u_ex*.log")) {

        Write-Verbose -Verbose ". FileName: $($item.Name)"

        #$stats[$server][$item.Name] = New-Object 'System.Collections.Generic.List[object]'

        $fs = [System.IO.File]::OpenRead($item.FullName)
        $sr = New-Object System.IO.StreamReader $fs

        $csv = while(-not $sr.EndOfStream) {
            $line = $sr.ReadLine()
            
            if($line.StartsWith('#')) { continue }

            $csv = $line | ConvertFrom-Csv -Delimiter " " -Header $header 
            
            $output = [pscustomobject]@{ 
                DateTime = "{0} {1}" -f $csv.date, $csv.time
                TimeTaken = $csv.'time-taken'
                Service = $csv.'cs-uri-stem'
                Method = $csv.'cs-method'
                Status = $csv.'sc-status'
            }

            #$stats[$server][$item.Name].Add($output) | Out-Null

            Write-Output $output
        }

        $csv | ConvertTo-Csv -Delimiter ';' -NoTypeInformation | Add-Content -Path $env:temp\csv.csv

        #Write-Verbose -Verbose ".. Found $($stats[$server][$item.Name].Count) lines"

        $sr.Close()
        $fs.Close()
    }
}