Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jayankandathil/b5e99bc7d0673be365f099843ea4429b to your computer and use it in GitHub Desktop.
Save jayankandathil/b5e99bc7d0673be365f099843ea4429b to your computer and use it in GitHub Desktop.
<#
.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