Tuesday, July 18, 2023

View IIS logs in grid view mode


 We can view today's iis logs in grid view mode using below ps script.


```sh
$IISLogs ="C:\\InetPub\\Logs\\LogFiles\\W3SVC1\\"
$Today=$(Get-Date -F 'yyMMdd')
Function Out-GridViewIISLog ($File) {
    $Headers = @((Get-Content -Path $File -ReadCount 4 -TotalCount 4)[3].split(' ') | Where-Object { $_ -ne '#Fields:' });
    Import-Csv -Delimiter ' ' -Header $Headers -Path $File | Where-Object { $_.date -notlike '#*' } | Out-GridView -Title "IIS log: $File";
};


Out-GridViewIISLog -File $(Join-path  $IISLogs "u_ex.$Today.log")

```

No comments:

Post a Comment