I've been reading the following article that describes how to change the web hosting plan for your site.
http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/
That seems to work fine but if I use the same command to change the web hosting mode (using property: "sku": "Free"
to "sku": "Standard"
) it doesn't give any error feedback and just returns with the unchanged (previous) stored configuration.
Command executed:
$standardServer=@{"sku" = "Standard"; }
Set-AzureResource -Name 'tmtest2' -ResourceGroupName 'Default-Web-JapanWest' -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01 -PropertyObject $standardServer
Anyone had any luck changing the web hosting mode using Powershell?
Edit: I also tried this link that exactly describes what I'm trying to achieve. However it did not work.
http://msdn.microsoft.com/en-us/library/dn654578.aspx
I figured this out. You need to create a hosting plan (with 'Standard' mode) first as a resource under a default resource group. Then you need to assign the website to the hostingplan.
Here's the full script:
Switch-AzureMode AzureResourceManager
Add-AzureAccount
$locations = @('East Asia', 'Southeast Asia', 'East US', 'East US 2', 'West US', 'North Central US', 'South Central US', 'Central US', 'North Europe', 'West Europe', 'Japan East', 'Japan West', 'Brazil South')
$websiteName = Read-Host 'What is the name of your website (without azurewebsites.net)' #tmtest2
$location = Read-Host 'What is the region location of the website'
if (-Not($locations -contains $location)) {
throw "location is incorrect, try one of these values: " + (($locations | select -expand $_) -join ", ")
}
$resourceGroupName = 'Default-Web-' + $location.Replace(' ', '');
#create a new web hosting plan - Small Standard machine
$hostingPlanName = $websiteName + 'HostingPlan';
$p=@{"name"= $hostingPlanName;"sku"= "Standard";"workerSize"= "0";"numberOfWorkers"= 1}
New-AzureResource -ApiVersion 2014-04-01 -Name $hostingPlanName -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/serverFarms -Location $location -PropertyObject $p -Verbose -Force
$r = Get-AzureResource -Name $websiteName -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01
echo $r
$p = $null;
$p = @{ 'serverFarm' = $hostingPlanName }
$r = Set-AzureResource -Name $websiteName -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01 -PropertyObject $p
#echo $r.Properties
if (-Not($r.Properties['sku'] -eq 'Standard')) {
throw 'script executed but sku has not been changed'
}
Start your Azure Resource Manager.
Add-AzureAccount
Switch-AzureMode AzureResourceManager
Get your Azure PowerShell API Version (This link shows how)
$DebugPreference='Continue'
Get-AzureResourceGroup
$DebugPreference='SilentlyContinue'
Get the Name, ResourceGroupName, and ResourceType of your Website Resources
Get-AzureResource | `
Where-Object { $_.ResourceType -like '*site*' } | `
Format-Table Name, ResourceGroupName, ResourceType
Change the Azure Website Hosting Plan for your target Website
Set-AzureResource
-Name the-website-name
-ResourceGroupName 'the-resource-group-name'
-ResourceType 'Microsoft.Web/sites'
-ApiVersion '2014-04-01-preview'
-PropertyObject @{ 'ServerFarm' = 'the-target-server-farm-name' }
Notes:
Get-AzureResource
in a similar way.Set-AzureResource
, you only need the ServerFarm
property.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With