powershell - 无法删除所有 Azure 网站连接字符串

标签 powershell azure azure-web-app-service

对于我的团队目前正在开发的网站,我们正在尝试编写一些 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

最佳答案

我知道现在已经很晚了。

我也遇到过同样的情况。我们可以更新应用程序设置,但不能更新连接字符串。我找到了解决方案。由于它没有答案,我认为更新它会很好..

根据 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"

关于powershell - 无法删除所有 Azure 网站连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29648327/

相关文章:

azure - Azure 事件日志中的错误事件 50000780,它们是什么意思?

powershell - Copy-Item 将目录及其内容复制到 UNC 路径

c# - 可以长时间保留对 Azure CloudTable 的引用吗?

azure - 尝试运行 Terraform Apply 时出错,Web 应用程序身份验证错误

azure - Azure 应用服务的 Terraform 模板,LinuxFxVersion 具有无效值

集成后,Azure Web 应用程序请求不通过 VNET

json 文件到 powershell 并返回到 json 文件

.net - 检查函数是否在递归函数调用中

macos - 在 AppleScript 或 PowerShell 中通过网络重新启动多台 Mac 的脚本?

azure - 在 Linux 上运行的 .NET Core Azure 函数中的 SharePoint CSOM