无法使用PS cmdlet Set-AzWebApp更新Azure应用程序服务的AppSettings

无法使用PS cmdlet Set-AzWebApp更新Azure应用程序服务的AppSettings,azure,powershell,azure-web-app-service,appsettings,Azure,Powershell,Azure Web App Service,Appsettings,这似乎是一个相当简单的任务,我有许多其他的例子,人们以类似的方式实现了它。但不知怎么的,这对我不起作用。这是我的剧本 $webapp = Get-AzWebApp -Name $webappname -ResourceGroupName $resourcegroupName $appset = $webapp.SiteConfig.AppSettings $appset $newsettings = new-object Microsoft.Azure.Management.WebSites

这似乎是一个相当简单的任务,我有许多其他的例子,人们以类似的方式实现了它。但不知怎么的,这对我不起作用。这是我的剧本

$webapp = Get-AzWebApp -Name $webappname -ResourceGroupName $resourcegroupName
$appset = $webapp.SiteConfig.AppSettings
$appset


$newsettings = new-object Microsoft.Azure.Management.WebSites.Models.NameValuePair
$newsettings.Name = "keyName"
$newsettings.Value = "MyValue"
   
$appset.Add($newsettings)
   
$newappset = @{}
$appset | ForEach-Object {
    $newappset[$_.Name] = $_.Value
}

Set-AzWebApp -ResourceGroupName $resourcegroupName -Name $webappname  -AppSettings $newappset
$webapp = Get-AzWebApp -Name $webappname -ResourceGroupName $resourcegroupName

Write-Output "New AppSettings:"
$webapp.SiteConfig.AppSettings
before/after都提供了相同的配置集,当我在Azure门户上检查它时,没有任何更改。我也没有收到任何错误。
任何人都可以看到脚本有什么问题。

这里似乎有报道

参考:

尽管使用了较旧的Az模块4.2.0,但我仍然能够观察到自己的行为。你可以试着进一步降级,试试看

或者,作为一种解决方法,我能够使用管理API满足我的需求

function update-webappsetting($web,$appsetting)
{
$token = (Get-AzAccessToken).Token 
$url = "https://management.azure.com" + $web.Id + "/config/appsettings?api-version=2020-06-01"
$headers = @{"Content-type"="application/json";"Authorization" = "Bearer $token"}
$body = '{"properties" :' + ($appsetting | ConvertTo-Json)  +  '}'


Invoke-WebRequest -Uri $url -Headers $headers -Body $body -Method PUT
}
要调用该函数,请执行以下操作:

update-webappsetting -web $web -appsetting $newappset 

如果
Set-AzWebApp-Name Name-ResourceGroupName RG-AppSettings设置
确实做了什么

添加到@Satya的响应中,另一个解决方法是传递其他
SiteConfig
属性,如
-httplogginenabled$true
中所述:

但是,此问题的修复程序现已推出,并作为最新
Az
模块版本
6.0.0
的一部分提供,该模块具有
Az.网站
版本
2.6.0
。我可以确认您的脚本在最新的
Az
模块中运行正常

请使用以下内容更新您机器上的模块:

Update-Module -Name Az

然后重试设置AppSettings。

我会检查一下,但是您附加的链接看起来像是钓鱼攻击网站。我想,我在复制和粘贴时输入了一个错误,这是一个github url。问题:15078@Alex谢谢你的修复。只是补充一下,有一个修复正在进行中。参考:您是否有机会检查提供的解决方案?
Update-Module -Name Az