【问题标题】:Not able to update AppSettings for Azure App Service using PS cmdlet Set-AzWebApp无法使用 PS cmdlet Set-AzWebApp 更新 Azure 应用服务的 AppSettings
【发布时间】:2021-05-21 10:46:26
【问题描述】:

这似乎是一项相当简单的任务,我还有许多其他示例,人们以类似的方式实现了它。但不知何故,这对我不起作用。这是我的脚本。

$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

之前/之后都提供了相同的配置集,当我在 Azure 门户上检查时没有任何变化。我也没有收到任何错误。 任何人都可以看到脚本有什么问题。

【问题讨论】:

    标签: azure powershell azure-web-app-service appsettings


    【解决方案1】:

    除了@Satya 的响应之外,另一种解决方法是传递其他SiteConfig 属性,如-HttpLoggingEnabled $true,如#15038 中所述:

    Set-AzWebApp -ResourceGroupName $resourcegroupName -Name $webappname -AppSettings $newappset -HttpLoggingEnabled $true
    

    但是,此问题的修复程序现已推出,并作为最新的Az 模块的一部分提供,版本为6.0.0,具有Az.Websites 版本2.6.0。我可以确认您的脚本可以与最新的 Az 模块配合使用。

    请更新您机器上的模块:

    Update-Module -Name Az
    

    然后重试设置 AppSettings。

    【讨论】:

      【解决方案2】:

      这里看起来像是一个报告的问题。

      参考:https://github.com/Azure/azure-powershell/issues/15078

      尽管使用的是较旧的 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 SETTING 做的一模一样

      【讨论】:

      • 我会检查一下,但是你附加的那个链接是什么,看起来像一个网络钓鱼攻击网站。
      • 我猜,我在复制和粘贴时有一个错字,它是一个 github url。问题:15078。 @Alex 感谢您修复它。
      • 只是补充一下,正在进行修复。参考:github.com/Azure/azure-powershell/issues/14998
      猜你喜欢
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 2017-11-05
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多