Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Created July 11, 2020 16:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shawnweisfeld/378ea7a2ecce00567afc95dc3af51ce6 to your computer and use it in GitHub Desktop.
## List all Application Insights Web Tests in a given resource group
## including test name and URL
# Variables
$TenantId = "" # Enter Tenant Id.
$ClientId = "" # Enter Client Id.
$ClientSecret = "" # Enter Client Secret.
$Resource = "https://management.core.windows.net/"
$SubscriptionId = "" # Enter Subscription Id.
$RG = "" # Enter Resource Group to look in.
$RequestAccessTokenUri = "https://login.microsoftonline.com/$TenantId/oauth2/token"
$body = "grant_type=client_credentials&client_id=$ClientId&client_secret=$ClientSecret&resource=$Resource"
$Token = Invoke-RestMethod -Method Post -Uri $RequestAccessTokenUri -Body $body -ContentType 'application/x-www-form-urlencoded'
# Get Web Tests
$WebTestApiUri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$RG/providers/microsoft.insights/webtests?api-version=2015-05-01"
$Headers = @{}
$Headers.Add("Authorization","$($Token.token_type) "+ " " + "$($Token.access_token)")
$WebTests = (Invoke-WebRequest -Method Get -Uri $WebTestApiUri -Headers $Headers).Content | ConvertFrom-Json
$Array = @()
foreach ($WebTest in $WebTests.value)
{
[XML] $WebTestXml = $WebTest.properties.Configuration.WebTest
foreach ($request in $WebTestXml.WebTest.Items)
{
$Array += [pscustomobject]@{ Name="$($WebTest.Name)"; Url="$($request.Request.Url)" }
}
}
$Array | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment