Listing and filtering IIS Logs in Powershell

From Tech-Wiki
Revision as of 15:51, 2 November 2023 by Fabricio.Lima (Talk | contribs)

Jump to: navigation, search

Back to Windows Server 2003/2008/20012


Parser and filter for IIS logs

$LogFiles = "C:\InetPub\Logs\LogFiles\W3SVC1\"
$Headers = @((Get-Content -Path (Get-ChildItem -Path $LogFiles -Filter '*.log').FullName -ReadCount 4 -TotalCount 4)[3].split(' ') | Where-Object { $_ -ne '#Fields:' });
Import-Csv -Delimiter ' ' -Header $Headers (Get-ChildItem -Path $LogFiles -Filter '*.log').FullName | Where-Object { $_.date -notlike '#*' } | Out-GridView -Title "IIS logs $LogFiles";