I am using Azure Powershell to create a new Azure Website:
New-AzureWebsite -Name MyWebsiteName
Azure creates it in the Default1
server farm, whereas I need it in DefaultServerFarm
.
Using the -location
parameter doesn't work to specify the server farm, because the Default1
and DefaultServerFarm
plans are both in "West US"
, and the location parameter does not take a server farm name as its value.
Using -slot
doesn't work either, thought I am not sure what is supposed to go in that parameter, it throws an EndpointNotFoundException
if I try to run it with DefaultServerFarm
as its value.
How can we create a new azure website with Powershell and set its server farm?
You cannot assign a web hosting plan when running the traditional New-AzureWebSite
.
To have this power and control, you have to use the newest version of Azure PowerShell and switch to AzureResourceManager mode.
Here is some tested PowerShell code:
Switch-AzureMode -Name AzureResourceManager
Add-AzureAccount
Select-AzureSubscription "Your Subscription Name"
New-AzureResource -Name NewWebSite `
-Location "West Europe" `
-ResourceGroupName 'Default-Web-WestEurope' `
-ResourceType 'Microsoft.Web/sites' `
-ApiVersion '2014-04-01-preview' `
-PropertyObject @{ 'ServerFarm' = 'DefaultServerFarm' }
Note, if your account is associated with multiple subscription you have to explicitly select the subscription under which the targeted Resource Group and Server Farm are. If you only have one subscription you can skip this line (Select-AzureSubscription
)
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