4

For a website my team are currently working on we're trying to write some PowerShell automation to temporarily override a connection string which is otherwise usually in Web.config, and then at a later point delete it.

However, using both the PowerShell cmdlets and the Azure REST APIs, we don't seem to be able to ever reset the connection strings set to be empty. Whenever we try to delete it either the command says it succeeds but doesn't delete it, or the requests is rejected as invalid.

It's possible to delete all the connection strings using the Management Portal, so what are we missing that means we can't do it programmatically?

Here's an example PowerShell command we're using that isn't doing what we want:

$website = Get-AzureWebsite $websiteName -slot $websiteSlot
$connectionStrings = $website.ConnectionStrings

$result = $connectionStrings.Remove(($connectionStrings | Where-Object {$_.Name -eq $connectionStringName}))

Set-AzureWebsite $websiteName -slot $websiteSlot -ConnectionStrings $connectionStrings
3
  • This looks like a bug to me. Commented Apr 16, 2015 at 2:33
  • Microsoft have recently stated that the new Azure portal is driven by the same public APIs, so how is it possible to delete settings from the UI but not through PowerShell? What is it that the UI does to delete settings? Commented Apr 16, 2015 at 8:12
  • 1
    I don't know, you would have to ask MSFT. But, this should work IMO. BTW, here is a link to an issue I opened last night on this if you want to follow. github.com/Azure/azure-powershell/issues/340 Commented Apr 16, 2015 at 13:17

2 Answers 2

4

I know this is really late.

I have faced the same situation.We are able to update the App settings but not the connection strings.I found the solution.Since it doesn't have an answer, I thought it would be good to update it..

As per the git-hub source, the hash-table(nested) needs to be in the format of

@{ KeyName = @{ Type = "MySql"; Value = "MySql Connection string"}};

after which I ran the code to update the App, it worked. Below is the whole code

$list =  @{ ConnectionString1 = @{ Type = "MySql"; Value = "MySql Connection string"}};

set-AzureRMWebAppSlot -ResourceGroupName "resourceGroup" -Name "devTest" -ConnectionStrings $list -slot "production"
Sign up to request clarification or add additional context in comments.

Comments

0

Another way which bypasses the parameter requirements of the Set-AzWebAppSlot cmdlet by passing the entire modified object.

$foo = Get-AzWebAppSlot -ResourceGroupName $Group -Name $AppName -Slot $SlotName

# Scriptblock coerced to predicate which always resolves true.
$foo.SiteConfig.ConnectionStrings.RemoveAll({ $True })
$foo | Set-AzWebAppSlot

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.