Given an Applications Insight Instrumentation key, get the name of the service in Azure

The older AzureRM PowerShell module is being replaced by the new cross-platform Az module. Based on the answers of @tobias and @ranieuwe, the following can fetch all your InstrumentationKeys using the newer module.

Install the Az module

Install-Module -Name Az -AllowClobber as admin, or

Install-Module -Name Az -AllowClobber -Scope CurrentUser as non-admin

Full instructions here: https://docs.microsoft.com/en-us/powershell/azure/install-az-ps

Remove older AzureRM module if needed

If you get warnings about both Az and AzureRM being installed/loaded, you can uninstall the old module by running the following as admin: Uninstall-AzureRm

Login to Azure and select Instrumentation Keys

Import-Module Az
Connect-AzAccount
Get-AzSubscription # will list all currently connected subscriptions
Select-AzSubscription <subscription-id>

# Retrieve all Instrumentation Keys along with name of AppInsights resource
Get-AzResource -ExpandProperties -ResourceType "microsoft.insights/components" | Select -ExpandProperty Properties | Select Name, InstrumentationKey

# Find a specific Instrumentation Key
Get-AzResource -ExpandProperties -ResourceType "microsoft.insights/components" | Select -ExpandProperty Properties | Where InstrumentationKey -eq "abe66a40-c437-4af1-bfe9-4b72bd6b94a1"| Select Name, InstrumentationKey

You can do this using PowerShell with the AzureRm cmdlets. If you are new to that, take a look here at the Azure Resource Manager.

You'll first need to login with Login-AzureRmAccount and then select a subscription with Select-AzureRmSubscription

The following script will get a list of the name of each Application Insights instance and its instrumentationkey:

Get-AzureRmResource -ExpandProperties -ResourceType "microsoft.insights/components"  -ResourceGroupName "your-resource-group" | select -ExpandProperty Properties  | Select Name, InstrumentationKey

This works as follows:

  1. Get all resources of type microsoft.insight/components from within your group
  2. Expand the properties of it
  3. Find the instrumentationkey and name in the properties

Using azure cloud shell (or any shell where you have azure-cli ^2.0.64 installed):

az extension add --name application-insights
az monitor app-insights component show --output table | grep <instrumentation_key>

This searches across your current subscription. You can see your current subscription with

az account show

There are probably fancier ways to use --query but the above approach is general purpose.