How to add an App Settings to existing Azure Web Application using Azure Power Shell

0 votes

I want to write a script that run using azure power shell to automate adding the Web Application configuration

Azure > MyWebApp > Application Settings > App settings

It's look like key = "value"

I write this script

###########################
# MyApp Config Automation #
###########################

#Begin

$subscriptionName="MySubscriptionName"
$webSiteName="MyWebAppName"
$storageAccountName="StorageAccountName"
########################################
$userName = "myaccount@outlook.com"
$securePassword = ConvertTo-SecureString -String "mypass" -AsPlainText -Force
#####################################
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
#####################################
Add-AzureAccount -Credential $cred 
Select-AzureSubscription -SubscriptionName $subscriptionName -Default
#####################################
Get-AzureWebsite -Name $webSiteName

#End

but i know that the above script is only get my web application, now i need to access MyWebApp > Application Settings > App settings and give the script file/array of my new App settings and the script check if there are any new App Settings key it will add it to App Settings, if there are any existing keys it will override it's value. What is the steps or APIS or can i do that with azure power shell?

This script can Automate creating new web application and adding App Settings to it:

##############################################
# Creating website and Adding Configs Script #
##############################################

$webSiteName="mywebsite"
$storageAccountName="storageaccount"
$subscriptionName="mysubsc"
$userName = "myaccount"
$securePassword = ConvertTo-SecureString -String "mypass" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
Add-AzureAccount -Credential $cred 
Select-AzureSubscription -SubscriptionName $subscriptionName -Default

New-AzureWebsite -Name $webSiteName
New-AzureStorageAccount StorageAccountName $storageAccountName -Location "South Central US"
$ClientId="dfgdf6"
$Password="ffefe"
$StorageAccountKey = Get-AzureStorageKey -StorageAccountName $storageAccountName
$AppSettings = @{"StorageAccountPrimary" = $StorageAccountKey.Primary;"StorageAccountSecondary" = $StorageAccountKey.Secondary;"ida:ClientId"=$ClientId;"ida:Password"=$Password}

Set-AzureWebsite -Name $webSiteName -AppSettings $AppSettings
Jun 13, 2018 in Azure by null_void
• 3,220 points
1,435 views

1 answer to this question.

0 votes

The example is for slot-specific settings, if you want global, use Get/Set-AzureRmWebApp and remove the -slot parameter

$myResourceGroup = 'PartsUnlimitedMRP'
$mySite = 'centpartsunlimited'

$webApp = Get-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -Slot production
$appSettingList = $webApp.SiteConfig.AppSettings

$hash = @{}
ForEach ($kvp in $appSettingList) {
    $hash[$kvp.Name] = $kvp.Value
}

$hash['NewKey'] = "NewValue"
$hash['ExistingKey'] = "NewValue"

Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $hash -Slot production
answered Jun 13, 2018 by club_seesharp
• 3,450 points

Related Questions In Azure

0 votes
1 answer

How to add Azure Virtual machine to an existing availability set?

You cannot associate an Availability Set to an existing ...READ MORE

answered Aug 10, 2018 in Azure by null_void
• 3,220 points
7,883 views
+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
2,214 views
0 votes
1 answer

How to automatically install Application Initialization in Azure Web Role (SDK v1.8) ?

Follow these steps - Install the feature using ...READ MORE

answered Apr 11, 2019 in Azure by Prerna
• 1,960 points
904 views
0 votes
1 answer
0 votes
1 answer

How to add co-admin to an azure subscription?

To assign a user as an administrator Sign ...READ MORE

answered Jan 23, 2020 in Azure by Sirajul
• 59,230 points
2,304 views
0 votes
1 answer

How to create an image from an existing disk in Azure?

Hi@akhtar, Sometimes we need to create a custom ...READ MORE

answered Nov 13, 2020 in Azure by MD
• 95,460 points
882 views
0 votes
1 answer

How to create a snapshot by copying an existing disk in Azure?

Hi@akhtar, Azure Managed Disk snapshots are used to create a point ...READ MORE

answered Nov 16, 2020 in Azure by MD
• 95,460 points
651 views
0 votes
1 answer

How to create an app service plan in Azure?

Hi@akhtar, An App Service plan defines a set of computing ...READ MORE

answered Nov 17, 2020 in Azure by MD
• 95,460 points
742 views
0 votes
1 answer

How can we connect Azure Web App to an Azure SQL Database?

Its easy now! Go to your Azure SQL ...READ MORE

answered Aug 9, 2018 in Azure by club_seesharp
• 3,450 points
6,805 views
+1 vote
2 answers

Getting an App pool timeout for azure web sites

Windows Azure Web Sites supports two modes, ...READ MORE

answered Aug 21, 2018 in Azure by Priyaj
• 58,020 points
3,455 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP