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,
7
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:
AllEnvironmentVariables.csv:
You can use the following Azure CLI commands to list configuration settings of App Services and Function Apps.
App Services:
- az webapp config show: Get the details of a web app’s configuration
- az webapp config appsettings list: Get the details of a web app’s settings
Function Apps:
- az functionapp config show: Get the details of an existing function app’s configuration
- az functionapp config appsettings list: Show settings for a function app
If you need to filter variables by type (App Settings, Azure SQL Database connection strings, custom connection strings, etc) take a look into the variable prefixes.