08 August 2022

Read IIS log file using PowerShell

 Actually you need just few lines

$file = '\\iisserver\c$\inetpub\logs\LogFiles\W3SVC1\u_ex220808.log'
$headers = (Get-Content $file | Select-Object -Skip 3 -First 1).Split(' ') | Select-Object -Skip 1
$result = Import-Csv $file ' ' -Header $headers | Where-Object date -NotLike '#*'
$result | ConvertTo-Csv -Delimiter `t -NoTypeInformation | Set-Clipboard

Output will be in clipboard (in this case it will be with tab separated for easy pasting into Excel or similar)

No comments:

Post a Comment