2

I am attempting to automate a workflow in our Azure environment.

We have several web applications with connectionstrings to several databases. Each new customer recives a new database.

I've hit a snag in the script with our connectionstrings. I want the script to update all web applications and add a new connectionstring for the newly created customer db.

The problem is "Set-Azurermwebapp -Name -ResourceGroup -ConnectionStrings" takes a hashtable which replaces any previously configured data.

I would only like to append a new connectionstring, or get the previously configered cstrings and add them to an array, then replacing all data.

Example code;

$test= @{"Type"="Custom"; "Value" = "TestValue"} 
$Connectionstring=@{"test"=$test }

Set-AzureRmWebApp 
        -Name "testapp" 
        -ResourceGroupName "testgrp" 
        -ConnectionStrings $Connectionstring"

Any ideas here?

2 Answers 2

10
$connStrings =  @{ 
   AzureWebJobsDashboard = @{ 
       Type = "Custom"; 
       Value = $AzureWebJobsDashboard 
   };
   AzureWebJobsStorage = @{ 
       Type = "MySql"; 
       Value = $connstring
   }
};

Set-AzureRMWebApp -Name $webServiceName -ResourceGroupName $rgName -ConnectionStrings $connStrings

Cannot Delete All Azure Website Connection Strings

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Srinivasa-Rao-Nalluri. I had hard time to find a good and simple example like yours. Perfect !
surely this just overwrites all existing connection strings? the OP wanted to know how to add new ones without removing any existing ones
I agree that Azure Powershell could be better at achieving this, you need to add all existing values to the hashtable, as it does a full overwrite for your webapp. Also makes it harder that when you get the values from the Get-AzureRmWebApp for example, the Siteconfig.ConnectionStrings property is a list, but when setting the values you need a hashtable as parameter. Maybe these were made by different teams at Microsoft without communication : )
0
#Add new connection string
$newConnString = New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.ConnStringInfo
$newConnString.Name = $ConnStringName
$newConnString.ConnectionString = $ConnStringValue
$newConnString.Type = $ConnStringType
$connStrings.Add($newConnString)

Set-AzureWebsite $WebAppName -ConnectionStrings $connStrings

You can download detail script from How to automatically create new connection strings for web applications Azure

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.