I want to see all the resources (Function Apps ect) that are using a specific App Insights. This is because I want to delete the app insights and recreate it. So far I cannot find out how to achieve this. I cannot find a way to do it on the portal or through Azure CLI.
Through Azure CLI closest I have gotten is:
az graph query -q "Resources | where isnotnull(properties['ConnectionString']) | where '<CONNECTIONSTRING>' contains properties['ConnectionString'] | project properties['ConnectionString'], name"
But I find most resources have a null ConnectionStrings, dosen't seem this would work through graph query. Any suggestions?
I came across https://learn.microsoft.com/en-us/answers/questions/742697/i-want-to-query-the-application-settings-on-a-func. Is this really the only variable option?
Thanks
Show all the resources linked to a app insights resource on Azure: -
After a workaround on your requirement, I found a way using PowerShell and the script is given below.
$app=Get-AzWebApp -ResourceGroupName "<resourcegroup>" -Name "KeyVaultPublish2023"
$setting_name=$app.SiteConfig.AppSettings.Name
$setting_value=$app.SiteConfig.AppSettings.value
if($setting_name -contains "APPINSIGHTS_INSTRUMENTATIONKEY"){
write-output "App insights exists"
if($setting_value -contains "<Give the required app insight to check>") #for eg: xxxxxx0-442f-8c0dr-2xxxx
{
write-output "App insight key is using the app insight resource."
}else{
write-output "Not matched."
}
}
Note: You can use either APPLICATIONINSIGHTS_CONNECTION_STRING
or APPINSIGHTS_INSTRUMENTATIONKEY
to check whether it is linked to the specific app insights resource. And I've checked for one app service under a resource group. To check all the resources, use
foreach ($app in $apps)
in the above code to make it work.