Evotec Services sp. z o.o., ul. Drozdów 6, Mikołów, 43-190, Poland

Reading IIS logs with PowerShell

IIS Logs Parser in PowerShell

Today I was reading Twitter, as I am pretty addicted to technology news when Adam Bacon mentioned that he's surprised that no one has rebuilt IIS Parser as pure PowerShell. While this is not entirely true, and some modules can do some parsing, I decided to try my luck. While doing it from scratch in PowerShell is possible, I opted to use an external C# library that does all the heavy lifting and is optimized for speed.

Using IISParser to read IIS Logs

So after about 1 hour of playing with the library and creating a new PowerShell module called IISParser, here we are.  We now have an easy-to-use PowerShell function to read IIS Logs.

Get-IISParsedLog -FilePath "C:\Support\GitHub\IISParser\Ignore\u_ex220507.log" | Select-Object -First 5 | Format-Table
Get-IISParsedLog -FilePath "C:\Support\GitHub\IISParser\Ignore\u_ex220507.log" | Select-Object -First 5 -Last 5 | Format-Table

Of course, when using Format-Table, we are not shown all the columns, but if we force the output using Format-List, we get all the IIS properties.

Get-IISParsedLog -FilePath "C:\Support\GitHub\IISParser\Ignore\u_ex220507.log" | Select-Object -First 5 -Last 5 | Format-List

Installing and updating IISParser

How do you install it? The easiest and most optimal way is to use PowerShellGallery. This will get you up and running in no time. Whenever there is an update, just run Update-Module, and you're done.

Install-Module IISParser
# Update-Module IISParser

However, if you're into code – want to see how everything is done, you can use GitHub sources. Please keep in mind that the PowerShellGallery version is optimized and better for production use. If you see any issues, bugs, or features that are missing, please make sure to submit them on GitHub.

Related Posts