Listing and filtering IIS Logs in Powershell

From Tech-Wiki
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 "$LogFiles\u_ex$(Get-Date -F 'yyMMdd').log" -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";