Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active March 12, 2021 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsscoder/3b1a5b39f528964b4cf9f03e6badced2 to your computer and use it in GitHub Desktop.
Save gsscoder/3b1a5b39f528964b4cf9f03e6badced2 to your computer and use it in GitHub Desktop.
PowerShell code to query Azure App Insights using REST API
$aiAppId = '00000000-0000-0000-0000-000000000000'
$aiApiKey = 'ehzgdrES4kBJNCuRUzcBfkuka5CGWkAr4hyhJ6y3'
$result = Invoke-RestMethod -Uri "https://api.applicationinsights.io/v1/apps/$aiAppId/query" `
-Method Post -UseBasicParsing `
-Headers @{
'x-api-key' = $aiApiKey
'content-type' = 'application/json'
} `
-Body '{"query": "traces | where timestamp <= ago(1m) | limit 10"}'
$result.tables[0].rows.Length | Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment