1

What is the equivalient of this code using New-AzAppServicePlan?

    az appservice plan create --resource-group $ServerFarmResourceGroupName `
        --name $AppServicePlanName `
        --is-linux `
        --location $ResourceGroupLocation `
        --sku $AppServicePlanTier `
        --number-of-workers $NumberOfWorkers

Is there really no way to create an App Service Plan using Az Powershell? Why can it only be done via Azure CLI or ARM?

I only found this answer, which basically uses ARM directly: How do I use Powershell to create an Azure Web App that runs on Linux?

Alex AIT
  • 17,361
  • 3
  • 36
  • 73

3 Answers3

2

There are some issues about this, suppose for now this is not supported for New-AzureRmAppServicePlan, however you could use New-AzureRmResource to create a linux plan. You could try the below command.

New-AzureRmResource -ResourceGroupName <>group name  -Location "Central US" -ResourceType microsoft.web/serverfarms -ResourceName <plan name>  -kind linux -Properties @{reserved="true"} -Sku @{name="S1";tier="Standard"; size="S1"; family="S"; capacity="1"} -Force

enter image description here

enter image description here

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • Yes, this is also the solution in the answer I linked to in my question... I was hoping for a different solution. – Alex AIT Jan 14 '20 at 07:56
  • Check this [comment](https://github.com/Azure/azure-powershell/issues/7096#issuecomment-507961265), suppose this feature will come online after a while. – George Chen Jan 14 '20 at 08:09
  • Thanks for this. I tried it with the Az module ie New-AzResource and it worked fine for me. There are a number of subtle things ones needs to watch though. @GeorgeChen, how does one enable container support? – Eniola Mar 28 '20 at 17:42
1

I originally used my script to create a ConsumptionPlan (Y1) through PowerShell and AzureCLI because I don't like when Azure put a generated name when creating a ConsumptionPlan.

Please find my solution to create a Linux App Service Plan (B1) using New-AzResource:

$fullObject = @{
   location = "West Europe"
   sku = @{
        name = "B1"
        tier = "Basic"
   }
   kind = "linux"
   properties = @{
        reserved = $true
   }
}

$resourceGroupName = "rg-AppServicePlanLinux"
$serverFarmName = "aspl-test"

Write-Host "Step 1: CREATING APP SERVICE PLAN B1:Basic named [$serverFarmName]"
# Create a server farm which will host the function app in the resource group specified
New-AzResource -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Web/serverfarms" -Name $serverFarmName -IsFullObject -PropertyObject $fullObject -Force

So I used the ARM template to understand which information you need to provide on the -PropertyObject parameter

It also now seems possible to do an App Service Plan Linux with New-AzAppServicePlan command since Az PowerShell 4.3.0 (June 2020) with the parameter -Linux

Az.Websites

  • Added safeguard to delete created webapp if restore failed in 'Restore-AzDeletedWebApp'
  • Added 'SourceWebApp.Location' for 'New-AzWebApp' and 'New-AzWebAppSlot'
  • Fixed bug that prevented changing Container settings in 'Set-AzWebApp' and 'Set-AzWebAppSlot'
  • Fixed bug to get SiteConfig when -Name is not given for Get-AzWebApp
  • Added a support to create ASP for Linux Apps
  • Added exceptions for clone across resource groups
  • Release Note: https://learn.microsoft.com/en-us/powershell/azure/release-notes-azureps?view=azps-5.6.0&viewFallbackFrom=azps-4.3.0#azwebsites-7

    New-AzAppServicePlan: https://learn.microsoft.com/en-us/powershell/module/az.websites/new-azappserviceplan?view=azps-5.6.0

    If you get "The Service is unavailable" after deploying your new Function app (Consumption Plan) with Azure CLI, please make sure the following statement from Microsoft: https://github.com/Azure/Azure-Functions/wiki/Creating-Function-Apps-in-an-existing-Resource-Group I waste the whole day because I got another Function App (Premium Plan) in the same resource group I used to deploy the Consumption one.

    HoLengZai
    • 301
    • 3
    • 13
    1

    This worked for me:

    Adding -Linux as a parameter to my command

    New-AzAppServicePlan -ResourceGroupName $RESOURCE_GROUP_NAME -Name $APP_SERVICE_PLAN_NAME -Location $RESOURCE_LOCATION -Linux -Tier $APP_SERVICE_PLAN_TIER -NumberofWorkers $APP_SERVICE_PLAN_WORKERS -WorkerSize $APP_SERVICE_PLAN_WORKER_SIZE
    

    Example:

    New-AzAppServicePlan -ResourceGroupName 'MyResourceGroup' -Name 'MyServicePlan' -Location 'northeurope' -Linux -Tier 'PremiumV2' -NumberofWorkers 2 -WorkerSize Medium
    
    halfer
    • 19,824
    • 17
    • 99
    • 186
    Promise Preston
    • 24,334
    • 12
    • 145
    • 143