Home > Enterprise >  az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or op
az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or op

Time:06-29

I am creating one runbook in my Azure automation account for scaling down the azure app services over the weekends. I am using the Az update command to update the app service plan. but I am getting error like "az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program". The same command is working fine in powershell command prompt. I have imported all Az dependency modules as well and AZ module as well. However, still facing the same issue. Please help me to fix this issue.

Please find my code below:

$connectionName = "AzureRunAsConnection"
Get-AutomationConnection -Name 'AzureRunAsConnection'
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    Add-AzAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 

}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

$subscription = "subscriptionid"
$resourceGroupName = "RG_name"
$appServicePlanName = "newappserviceplan"
$sku = "B1"

#Powershell az command to sclale down
az appservice plan update -name $appServicePlanName --resource-group $resourceGroupName --subscription $subscription --sku $sku

Write-Output "The app service plan is downgraded to $sku"

CodePudding user response:

It's this line which is tripping it up

az appservice plan update -name $appServicePlanName --resource-group $resourceGroupName --subscription $subscription --sku $sku

Like @Sage Poupre has said, that not a PowerShell cmdlet, it's the Azure CLI command.

You will want to use Set-AzAppServicePlan instead

The PowerShell equivalent isn't exactly the same as it doesn't accept SKU but instead needs Tier and Workers to make up B1.

Set-AzAppServicePlan -Name $appServicePlanName -ResourceGroup $resourceGroupName -Tier Small -Workers 1

https://docs.microsoft.com/en-us/powershell/module/az.websites/set-azappserviceplan

Is there a way to upgrade an azure app service plan using powershell?

Let us know if that works

CodePudding user response:

We can use below powershell command to update the app service plan:

Set-AzAppServicePlan -Name $appServicePlanName -ResourceGroupName $resourceGroupName -Tier BasicB1 -NumberofWorkers 1 -WorkerSize Small

We can use Small, Medium and Large Workersizes,

for example, if we need to update the app service plan to S1, then I need to consider Tier as "StandardS1" and Worker size as "Small". Similarly for S2 we can mention the worker size as "Medium".

  • Related