Changing Azure Hosting Plans with PowerShell


I recently had a customer ask me how to upgrade hosting plans for a single Azure Web Site from the Free mode to the Standard mode so that they could evaluate the new deployment slot feature that is currently in preview today.

With much confidence, I pointed him to the Azure portal and showed him where he could change the hosting plan mode. When I did this myself, I saw what his concern was. It was updating all the web sites I had to the Standard hosting mode.

Here are the two simple test web sites I have created to illustrate what I’m talking about. I created two web sites running in the Free mode.

 

 

 

I then clicked on my first web site “shadpersonaltestsite1” in hopes of changing its hosting plan to Standard so I can take advantaging of using deployment slots. I click on the Scale tab in the portal and select the Standard Web Hosting Plan Mode. This is where I should have realized I was going to be placing both web sites. I can clearly see which sites are listed. However, I was just clicking away and I hit Save at the bottom

 

 

However, in case you missed that obvious note, as I just did. The Azure portal does notify in the confirmation screen about the affected sites. However, I only one shadpersonaltestsite1 to change plans. So what gives?

 

In doing a little research on the web, I found this post on Stack Overflow http://stackoverflow.com/questions/24892220/change-azure-website-web-hosting-plan-mode-using-powershell . I took that reference and created my own little PowerShell script that helped me accomplish what I want. Which is to only change the hosting mode of a single web application in Azure.

 

 Switch-AzureMode AzureResourceManager
Add-AzureAccount

#Name of the location your web site is running in
$loc = 'South Central US';
#name of the web site you want to upgrade from Free to Standard or Basic. I did Standard in this case.
$site = "shadpersonaltestsite1";
#this will create the default resource group name.
$rgn = 'Default-Web-SouthCentralUS'
#let's name a new hosting plan name. I used my web site name and the very creative 'StandardHostingPlan'
$hpn = $site + 'StandardHostingPlan';
#let's set the plan properties, most importanly the sku 'Standard'
$plan=@{"name"= $hpn;"sku"= "Standard";"workerSize"= "0";"numberOfWorkers"= 1}
#lets create that Azure Resrouce
New-AzureResource -ApiVersion 2014-04-01 -Name $hpn -ResourceGroupName $rgn -ResourceType Microsoft.Web/serverFarms -Location $loc -PropertyObject $plan -Verbose -Force

#now let's go and get the azure resource we want to update. In this case, my shadpersonaltestsite1
$res = Get-AzureResource -Name $site -ResourceGroupName $rgn -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01
#let's update the properties and call Set-AzureResource
$prop = $null;
$prop = @{ 'serverFarm' = $hpn }
$res = Set-AzureResource -Name $site -ResourceGroupName $rgn -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01 -PropertyObject $prop

 

Now I can see that I have my shadpersonaltestsite1 in Standard Mode and the other still in Free Mode.

 

 

Let’s look a little deeper at what just actually did. First, let’s look at the properties of the Standard Hosting Plan we just created. Notice in the properties the name and sku properties we set.

Get-AzureResource -Name shadpersonaltestsite1StandardHostingPlan -ResourceGroupName 'Default-Web-SouthCentralUS' -ResourceType Microsoft.Web/serverFarms -ApiVersion 2014-04-01

 

 

Now, let’s look at the shadpersonaltestsite1 web site. Notice the serverFarm and webHostingPlan properties for this web site.

Get-AzureResource -Name shadpersonaltestsite1 -ResourceGroupName 'Default-Web-SouthCentralUS' -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01

 

Now, let’s look at the shadpersonaltestsite2 web site. Notice that the serverFarm and webHostingPlan are set to the Default.

 

Get-AzureResource -Name shadpersonaltestsite2 -ResourceGroupName 'Default-Web-SouthCentralUS' -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01
 
 
Comments (0)

Skip to main content