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
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}
I tried another tweak (which I forgot) and it said that the $PropertiesObject object was not in the right format.
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"?