【问题标题】:Clearing Azure web app config settings from PowerShell从 PowerShell 清除 Azure Web 应用程序配置设置
【发布时间】:2018-01-03 13:12:46
【问题描述】:

我正在尝试使用 Azure PowerShell 清除 Web 应用站点配置上的所有应用程序设置和连接字符串。 API 似乎不支持这一点。

我尝试过使用:

Set-AzureRmWebApp -ResourceGroupName $resourceGroupName -Name $siteName -AppSettings @{}

但这会引发错误,因为字典是空的。

我试过使用这个命令:

Set-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceName "$siteName/appsettings" -ResourceType "Microsoft.Web/sites/config" -ApiVersion 2016-08-01 -Properties @{}

但我收到一条错误消息<Error><Message>The requested resource does not support http method 'GET'.</Message></Error>

我也试过这个:

Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceName "$siteName/appsettings" -ResourceType "Microsoft.Web/sites/config" -ApiVersion 2016-08-01 -Action "Post" -Parameters @{}

但我再次收到此错误:

Cannot validate argument on parameter 'Parameters'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again.

还有其他清除所有应用设置的方法吗?

以前有一种方法可以使用Get-AzureRmWebApp检索webapp,在本地编辑,然后使用Set-AzureRmWebApp发布对象,实际上帮助文档中还是说有-WebApp参数,但是没有不再存在于最新的 Azure PowerShell 中。

【问题讨论】:

  • 是否尝试过获取资源以查看其外观?然后只发送一个空集合?
  • 我在实验室测试,null 值不允许传递给-AppSettings。

标签: powershell azure azure-powershell


【解决方案1】:

我在我的实验室测试,-AppSettings 不允许空哈希值。我建议你可以给它传递一个值。它将删除所有原始应用程序设置并创建一个新的密钥对。如下:

$appsettings=@{
    'test'="test"
}

Set-AzureRmWebApp -ResourceGroupName $resourceGroupName -Name $siteName -AppSettings $appsettings

您可以使用Azure Cli 2.0 删除应用设置的另一种解决方案。例如:

az webapp config appsettings delete -n shuicli -g shuiapp --setting-names test shui

更新:

您也可以使用API 删除应用程序设置。

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/appsettings?api-version=2016-08-01

【讨论】:

  • 如果 Azure CLI 支持删除应用程序设置,门户也支持,那么可以手动调用一些 API 方法来执行此操作是有道理的。但我不确定它是否记录在任何地方
  • @TrevorElliott 也许你可以看看这个API和这个answer
  • @TrevorElliott 使用az webapp config appsettings delete -n shuicli -g shuiapp --setting-names test --debug 你可以看到cli如何调用API。
  • @TrevorElliott 我建议你可以使用 Power Shell 来调用这个 API。对不起,我不太擅长 API,也许你可以问一个新问题。
  • @TrevorElliott 这是 cli 调用 API 的 result。希望对您有所帮助。
猜你喜欢
  • 2011-05-21
  • 2020-08-01
  • 2023-02-26
  • 1970-01-01
  • 2010-09-06
  • 1970-01-01
  • 1970-01-01
  • 2020-08-13
  • 1970-01-01
相关资源
最近更新 更多