How to create Azure WebApp in App Service using Powershell commands

I am trying to create Azure Web App in App Service environment using Powershell commands

I still can't see to indicate that my app serving framework should be used with the New-AzureWebApp or New-AzureAppServicePlan commands

In the web portal, you specify the App Service environment as a location ... but that is not possible with Powershell commands (they confirm the location is a valid "regular" Azure location).

+3


source to share


3 answers


To answer my own question:

I found that I can create a new web application using the New-AzureResourceGroup command and a custom JSON template. I couldn't find the templates that provided the web app in ASE in the gallery, but by referring to developing a template that uses the portal and modifying the gallery template Microsoft.WebSite.0.3.17-preview.json from the gallery, I could create a WebApp using the command:

New-AzureResourceGroup -Name $ResourceGroupName -Location "Australia Southeast" -TemplateFile $TemplateFile -siteName $SiteName -hostingPlanName $HostingPlanName -hostingEnvironment $HostingEnvironment -siteLocation "Australia Southeast" -workerSize 0 -sku "Premium"

With the $ TemplateFile variable containing the path to the following template file:

http://pastebin.com/VefC0Dz2

This is just a 0.3.17-preview template from the gallery with the following changes:



Add hostingEnvironment parameter

"parameters": { "hostingEnvironment": { "type": "string", "defaultValue": "" },

Add the hostingEnvironment property to the Microsoft.Web / serverfarms resource:

"resources": [ { "apiVersion": "2014-06-01", "name": "[parameters('hostingPlanName')]", "type": "Microsoft.Web/serverfarms", "location": "[parameters('siteLocation')]", "properties": { "name": "[parameters('hostingPlanName')]", "sku": "[parameters('sku')]", "workerSize": "[parameters('workerSize')]", "hostingEnvironment": "[parameters('hostingEnvironment')]", "numberOfWorkers": 0 } }, { "apiVersion": "2014-06-01", "name": "[parameters('siteName')]", "type": "Microsoft.Web/sites", "location": "[parameters('siteLocation')]", "tags": { "[concat('hidden-related:', '/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty" }, "dependsOn": [ "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]" ], "properties": { "name": "[parameters('siteName')]", "serverFarm": "[parameters('hostingPlanName')]", "hostingEnvironment": "[parameters('hostingEnvironment')]" } },

I guess this can probably also be done using the Add-AzureResource Command Code, but I haven't tried that yet.

+5


source


Microsoft added CommandManager ResourceManager to PowerShell. This enables deployment. The website can be created in PowerShell using the following commands:

New-AzureRmResource -Location "West Europe" -Properties $props 
-ResourceName "Site1" -ResourceType "microsoft.web/sites"
-ResourceGroupName "ResourceGrp1" -Force

      

You need to create an object for properties:



$props = @{
HostingEnvironmentId ='/subscriptions/xyz/resourceGroups/ResourceGroup1/providers/Microsoft.Web/hostingEnvironments/ASE1
ServerFarmId = '/subscriptions/XXXX/resourceGroups/EDSGRP1/providers/Microsoft.Web/serverfarms/ASP1'
HostingEnvironment = ResourceGroup1
ClientCertEnabled ='True'
}

      

You can get an idea of ​​what property properties are used by using Get-AzureRMResource in the outbound site.

+2


source


Microsoft recently changed Azure Websites to Azure WebApps. However, the PowerShell cmdlet commands remain the same.

So, you will need to use New-AzureWebsite

0


source







All Articles