AzureRM Web App-如何使用Powershell控制插槽设置 [英] AzureRM Web App - How to control the slot setting with Powershell

查看:102
本文介绍了AzureRM Web App-如何使用Powershell控制插槽设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Powershell设置Azure Web应用程序的连接字符串和应用程序设置.我希望这些设置保留在插槽中,而不是在交换时保留在应用程序中.

I would like to set the connection strings and app settings of my Azure web app using powershell. And I would like those settings to stick with the slot, and not with the app when it is swapped.

应用设置的代码如下所示,并且可以正常工作:

The code for app settings looks like this and it works:

$PropertiesObject = @{"SMTPUser"="myuser"; "SMTPPassword"="secretpwd";}
$webAppName = "mywebapp"
$slotName = "demo"
$resourceGroupName = "myResourceGroup"

New-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/slots/config -ResourceName $webAppName/$slotName/appsettings -ApiVersion 2015-08-01 -Force


$stickSlotConfigObject = @{"connectionStringNames"=@(); "appSettingNames" = @("SMTPUserName","SMTPPassword");}

$result = Set-AzureRmResource -PropertyObject $stickSlotConfigObject -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $webAppName/slotConfigNames -ApiVersion 2015-08-01 -Force

这有效.当我转到Azure门户中Web应用程序的插槽刀片时,根据需要选中了插槽设置"复选框.

This works. When I go to the slot blade of the web app in the Azure portal, the "Slot Setting" check box is checked as I want it to be.

我正在努力设置连接字符串,以同时选中插槽设置"框.我尝试了以下方法,

I'm struggling with how to set the connection strings to also have the "slot setting" box checked. I tried the following,

$PropertiesObject =  @{ 
  AzureWebJobsStorage = @{  
    Type = "Custom"; 
    Value = "somestring"
  };
  Common = @{   
    Type = "SQLAzure"; 
    Value = "somedatabasestring" 
  };
};

$webAppName = "mywebapp"
$slotName = "demo"
$resourceGroupName = "myResourceGroup"

New-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/slots/config -ResourceName $webAppName/$slotName/appsettings -ApiVersion 2015-08-01 -Force

$stickSlotConfigObject = @{"appSettingNames"=@();"connectionStringNames"=@("AzureWebJobsStorage","Common"); }

$result = Set-AzureRmResource -PropertyObject $stickSlotConfigObject -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $webAppName/appsettings -ApiVersion 2015-08-01 -Force

这不起作用.我收到以下错误:

This did not work. I got the following error:

New-AzureRmResource : {"Code":"BadRequest","Message":"The parameter properties has an invalid value.","Target":null,"Details":[{"Message":"The parameter properties has an invalid value."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","Message":"The parameter properties has an invalid value.","ExtendedCode":"51008","MessageTemplate":"The parameter {0} has an invalid value.","Parameters":["properties"],"InnerErrors":null}}],"Innererror":null}

我尝试了另一个调整(我忘记了),它说$ PropertiesObject对象的格式不正确.

I tried another tweak (which I forgot) and it said that the $PropertiesObject object was not in the right format.

如何在Powershell中对其进行编码,以便可以检查Web应用程序连接字符串的插槽设置复选框(或将其配置为粘性"?)?

How do I code it in Powershell so that I can check the slot setting check box of a web app connection string (or configure it as "sticky"?

推荐答案

请尝试使用以下代码将连接字符串设置为插槽的固定设置.它对我来说正常工作.有关使用PowerShell ARM方式自动化Azure WebApp的详细信息,请参考

Please have a try with the following code to set connection string as sticky setting for slot. It works correctly for me. More info about automating Azure WebApps with PowerShell ARM way please refer to the document.

$connectionString = @{}
$webAppName = "Web AppName"
$resourceGroup ="Resource Group Name"
$slotName ="slot Name" 
$connectionString.Add("AzureWebJobsStorage", @{ value = "The Actual connecting string here" ; Type = 3 }) #Custom
$connectionString.Add("Common", @{ value = "The Actual connecting string here" ; Type = 2 }) #Azure SQL

  Login-AzureRmAccount
  # creat slot connection string
  New-AzureRmResource -PropertyObject $connectionString `
  -ResourceGroupName $resourceGroup `
  -ResourceType "Microsoft.Web/sites/slots/config" `
  -ResourceName "$webAppName/$slotName/connectionstrings" `
  -ApiVersion 2015-08-01 -Force

  # set connection string  as sticky setting 
  $stickSlotConfigObject =  @{"connectionStringNames" = @("AzureWebJobsStorage","Common")} #connection string Name
  Set-AzureRmResource -PropertyObject $stickSlotConfigObject `
  -ResourceGroupName $resourceGroup `
  -ResourceType Microsoft.Web/sites/config `
  -ResourceName  $webAppName/slotConfigNames `
  -ApiVersion 2015-08-01 -Force

这篇关于AzureRM Web App-如何使用Powershell控制插槽设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆