Last active
July 5, 2022 12:32
-
-
Save criscunhasantos/9d07466a84920d0a94a295e8c04542e6 to your computer and use it in GitHub Desktop.
IIS Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Converts plain text IIS logs into a ps Object | |
.DESCRIPTION | |
Converts plain text IIS logs into a ps Object | |
.EXAMPLE | |
Get-ChildItem '<path to logs>\*.log' | Convert-IISLogsToObject | Sort-Object c-ip -Unique | |
.EXAMPLE | |
Convert-IISLogsToObject -path (Get-ChildItem '<path to logs>\*log') | Where-Object { $_.'cs-username' -eq '<userName>' } | Sort-Object c-ip -Unique | |
.NOTES | |
General notes | |
.AUTHOR | |
Ben Taylor - 09/07/2016 | |
#> | |
function Convert-IISLogsToObject { | |
[CmdletBinding()] | |
[OutputType([System.Management.Automation.PSCustomObject])] | |
Param( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[ValidateScript({ Test-Path -Path $_ })] | |
[string[]] | |
$path | |
) | |
Process { | |
forEach ($filePath in $path) { | |
$headers = (Get-Content -Path $filePath -TotalCount 4 | Select-Object -First 1 -Skip 3) -replace '#Fields: ' -split ' ' | |
Get-Content $filePath | Select-String -Pattern '^#' -NotMatch | ConvertFrom-Csv -Delimiter ' ' -Header $headers | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. "\Convert-IISLogsToObject.ps1" | |
cd C:\inetpub\logs\LogFiles\W3SVC1 | |
$iis = gci | sort LastWriteTime -Descending | select -First 7 | Convert-IISLogsToObject | |
$iis | group cs-uri-stem | sort count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment