Azure PowerShell: Scale App Service Plan to Save Money

Here’s a bit of PowerShell to scale your Azure App Service down to save money. This task could be scheduled to “size down” at night, and “size up” for business hours.

$AppServicesJson = @"
  { "ResourceGroupName": "MyAppServiceGroup", "NumberOfWorkers": 1, "AppServiceTier": "Basic", "WorkerSize": "Small" }
$AppServices = ConvertFrom-Json -InputObject $AppServicesJson
$AppServices | ForEach-Object {
  $AppServicePlan = Get-AzureRmAppServicePlan -ResourceGroupName $_.ResourceGroupName -ErrorAction SilentlyContinue # Expects only one per resource group 
  If ($null -eq $AppServicePlan) {
    Write-Warning "No AppService Plan found for Resource Group $($_.ResourceGroupName)."
  } Else {
    Write-Output "Setting $($AppServicePlan.Name) plan in resource group $($_.ResourceGroupName) to $($_.AppServiceTier) $($_.WorkerSize) with $($_.NumberOfWorkers) worker(s)..."
    Set-AzureRmAppServicePlan -ResourceGroupName $AppServicePlan.ResourceGroup -Name $AppServicePlan.Name -Tier $_.AppServiceTier -WorkerSize $_.WorkerSize -NumberofWorkers $_.NumberOfWorkers

Hope this helps!

This entry was posted in Azure, PowerShell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *