1
votes

I want to create an App Service Plan (Consumption) through powershell task. For this i used Azure Powershell task, And my code is:

[cmdletbinding()]
    param (
        $AppServicePlanLocation, 
        $AppServicePlanResourceGroupName,
        $AppServicePlan_Name
    )

$location = $AppServicePlanLocation
$resourceGroupName = $AppServicePlanResourceGroupName
$appServicePlanName = $AppServicePlan_Name

Write-Host "SafeCreateAppServicePlan.Parameter:location: $location"
Write-Host "SafeCreateAppServicePlan.Parameter:resourceGroupName: $resourceGroupName"
Write-Host "SafeCreateAppServicePlan.Parameter:appServicePlanName: $appServicePlanName"

$SkuName = "Y1"
$SkuTier = "Dynamic"
$WebAppApiVersion = "2015-08-01"

$fullObject = @{
    location = $location
    sku = @{
        name = $SkuName
        tier = $SkuTier
    }
}

Write-Host "Ensuring the $appServicePlanName app service plan exists"
$plan = Get-AzureRmAppServicePlan -Name $appServicePlanName -ResourceGroupName $resourceGroupName -ErrorAction SilentlyContinue
if(-not $plan) {
    Write-Host "Creating $appServicePlanName app service plan"
    New-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/serverfarms -Name $appServicePlanName -IsFullObject -PropertyObject $fullObject -ApiVersion $WebAppApiVersion -Force
}
else {
    Write-Host "$appServicePlanName app service plan already exists"   
}

But it is giving error: The term 'Get-AzureRmAppServicePlan' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Azure Powershell task is not recognizing Get-AzureRmAppServicePlan command.

Note: I have not used simple powershell task, I have used Azure Powershell task.

2

2 Answers

2
votes

If you are using the latest version of the task - replace all the *AzureRM* commands with *Az* (or enable backwards compatibility) as this is the supported Azure Powershell module, current (the AzureRM one is depreciated and no longer supported).

https://docs.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-3.3.0

ps. If you are using a previous version of the task - AzureRM should work

0
votes

You don't mention what Task version of the Azure PowerShell task you are using, or the context the agent is running in, Hosted\Private. Both those can effect if the module would be available.

Can check and see if the AzureRM.Websites Module is available.

$ Get-Module Azure* -list | Select-Object Name,Version,Path

You may need to manually load the module, or specify an older version of the Azure PowerShell task, as the AzureRM modules aren't automatically available when using the newer version of the task.