How to Configure Application Insight connection string to WebApp Appsetting using powershell script

VIKARAN KARWASRA 0 Reputation points
2023-11-20T06:36:04.6966667+00:00

Hi All,
How to Configure Application Insight connection string to WebApp Appsetting using powershell script.
I have already configured through ARM template. However, I want to know how we can configure Application_Insight_connection string through powershell.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,364 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,010 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Luis Arias 7,686 Reputation points
    2023-11-20T11:00:46.46+00:00

    Hi @VIKARAN KARWASRA ,
    I prepared this powershell code to enable application insight in web can you test and verify if is working for you:

    # Connect to Azure
    Connect-AzAccount
    
    # Naming variables
    $webappName="Your WebApp"
    $webappRgName="RG of your Web App"
    $appiName="Application Insight Name"
    $appiRgName="RG Name of  your Application Insight"
    
    $appInsights = Get-AzApplicationInsights -ResourceGroupName $appiRgName -Name $appiName
    $instrumentationKey = $appInsights.InstrumentationKey
    $appSettings = @{"ApplicationInsightsAgent_EXTENSION_VERSION"="~3"; "APPINSIGHTS_INSTRUMENTATIONKEY"=$instrumentationKey}
    Set-AzWebApp -ResourceGroupName $webappRgName -Name $webappName -AppSettings $appSettings
    
    

    Let me know if this solve your question,

    Cheers,

    Luis Arias


    If the information helped address your question, please Accept the answer.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.