<# .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"