gpt4 book ai didi

powershell - 从 PowerShell 清除 Azure Web 应用程序配置设置

转载 作者:行者123 更新时间:2023-12-03 00:10:28 25 4
gpt4 key购买 nike

我尝试使用 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 中不再存在。

最佳答案

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

$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

关于powershell - 从 PowerShell 清除 Azure Web 应用程序配置设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48067815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com