Created
October 20, 2017 13:17
-
-
Save jayankandathil/b5e99bc7d0673be365f099843ea4429b to your computer and use it in GitHub Desktop.
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 Azure Application Gateway access logs in JSON format to CSV | |
.DESCRIPTION | |
This PowerShell script was tested with PowerShell v5.1 | |
.NOTES | |
AUTHOR: Jayan Kandathil (Adobe AEM Managed Services) | |
LASTEDIT: October 20, 2017 | |
#> | |
$Watch = [System.Diagnostics.Stopwatch]::StartNew() | |
$path = "G:\TEMP\" | |
$filename = "PT1H" | |
$json = Get-Content -Path $path$filename.json | ConvertFrom-Json | |
$columns = "`"timestamp`",`"instanceId`",`"clientIP`",`"clientPort`",`"httpMethod`",`"requestUri`",`"requestQuery`",`"userAgent`",`"httpStatus`",`"httpVersion`",`"receivedBytes`",`"sentBytes`",`"timeTaken`",`"sslEnabled`"" | |
Write-Host $columns | |
Add-Content $path$filename.csv $columns | |
foreach ($record in $json.records) | |
{ | |
foreach ($property in $record.properties) | |
{ | |
$output = "`"" + $record.time + "`",`"" + $property.instanceId + "`",`"" + $property.clientIP + "`",`"" + $property.clientPort + "`",`"" + $property.httpMethod + "`",`"" + $property.requestUri + "`",`"" + $property.requestQuery + "`",`"" + $property.userAgent + "`",`"" + $property.httpStatus + "`",`"" + $property.httpVersion + "`",`"" + $property.receivedBytes + "`",`"" + $property.sentBytes + "`",`"" + $property.timeTaken + "`",`"" + $property.sslEnabled + "`"" | |
Write-Host $output | |
Add-Content $path$filename.csv $output | |
} | |
} | |
$Watch.Stop() | |
Write-Host -foregroundcolor Yellow "Processed" $json.records.Count "records" | |
Write-Host -foregroundcolor Yellow "Took $($Watch.Elapsed.TotalSeconds) seconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment