从 PowerShell 清除 Azure Web 应用配置设置

Clearing Azure web app config settings from PowerShell

我正在尝试使用 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,在本地编辑它,然后 post 使用 Set-AzureRmWebApp 获取对象,事实上帮助文档仍然说有一个 - WebApp 参数,但在最新的 Azure PowerShell 中已不存在。

我在我的实验室测试,-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