对于我的团队目前正在研究的网站,我们正在尝试编写一些PowerShell自动化功能来临时替代通常在Web.config中使用的连接字符串,然后在以后将其删除。
但是,同时使用PowerShell cmdlet和Azure REST API,我们似乎无法将连接字符串设置为空。每当我们尝试删除它时,该命令要么说它成功但不删除它,要么该请求被视为无效请求。
可以使用管理门户删除所有连接字符串,那么我们遗漏了什么,这意味着我们无法以编程方式进行操作?
这是我们正在使用的示例PowerShell命令,没有执行我们想要的操作:
$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
最佳答案
我知道这真的很晚。
我也遇到过同样的情况,我们能够更新App设置但不能更新连接字符串。我找到了解决方案。由于它没有答案,所以我认为更新它会很好。
根据git-hub source,哈希表(嵌套)的格式必须为
@{ KeyName = @{ Type = "MySql"; Value = "MySql Connection string"}};
之后,我运行了代码以更新该应用程序,它开始工作了。下面是整个代码
$list = @{ ConnectionString1 = @{ Type = "MySql"; Value = "MySql Connection string"}};
set-AzureRMWebAppSlot -ResourceGroupName "resourceGroup" -Name "devTest" -ConnectionStrings $list -slot "production"