Azure powershell – move a webapp from one app service plan to another

Updated 7/12/2021

Move a list of apps in one app service plan to another. I was consolidating some app services into one app plan to save some money. Found my old script and updated it. It’s super simple but does the job.

Login-AzAccount
$sub = 'yer sub name'
Set-AzContext -SubscriptionName $sub

$slotname = 'Production'
$rg = 'Resource Group Name'
$AppPlanMoveTo = 'App service plan to move to'

#Get list of apps
$serverfarm = '/subscriptions/sub-id/resourceGroups/RG/providers/Microsoft.Web/serverfarms/App service plan moving from'
$apps = (Get-AzWebApp -ResourceGroupName $rg | where {$_.ServerFarmId -eq $serverfarm}).Name

ForEach ($app in $apps) {
    Set-AzWebAppSlot -Name $app -Slot $slotname -ResourceGroupName $rg -AppServicePlan $AppPlanMoveTo    
}

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.