azureazure-functionsazure-web-app-serviceazure-appservice

Azure Powershell - how to list all Environment variables


In Azure Portal I have several "Function apps" and "App Services" that have Environment variables. Environment variables can have "App Settings" and "Connections strings".

I like to list "Environment Variables", for all services, by Name and Value.
My goal is to check for any wrong settings so I like all "Environment Variables" in a long list.

How can I do this from Azure Cloud Shell? Thanks,


Solution

  • To list all Environment variables from all App Services and Function Apps, you can make use of below sample PowerShell script:

    Connect-AzAccount
    
    $rGs = Get-AzResourceGroup
    $allSettings = @()
    
    foreach ($rg in $rGs) {
        $webApps = Get-AzWebApp -ResourceGroupName $rg.ResourceGroupName
    
        foreach ($webApp in $webApps) {
            $appSettings = (Get-AzWebApp -ResourceGroupName $rg.ResourceGroupName -Name $webApp.Name).SiteConfig.AppSettings
            foreach ($setting in $appSettings) {
                $allSettings += [pscustomobject]@{
                    ServiceName     = $webApp.Name
                    ResourceGroup   = $rg.ResourceGroupName
                    SettingName     = $setting.Name
                    SettingValue    = $setting.Value
                    SettingType     = "AppSetting"
                }
            }
    
            $connectionStrings = (Get-AzWebApp -ResourceGroupName $rg.ResourceGroupName -Name $webApp.Name).SiteConfig.ConnectionStrings
            foreach ($conn in $connectionStrings) {
                $allSettings += [pscustomobject]@{
                    ServiceName     = $webApp.Name
                    ResourceGroup   = $rg.ResourceGroupName
                    SettingName     = $conn.Name
                    SettingValue    = $conn.ConnectionString
                    SettingType     = "ConnectionString"
                }
            }
        }
    }
    
    $allSettings | Export-Csv -Path "$HOME/AllEnvironmentVariables.csv" -NoTypeInformation #exported to csv file
    $allSettings # print values to terminal
    

    Response:

    enter image description here

    AllEnvironmentVariables.csv:

    enter image description here