Azure powershell – move webapp slot to new app service plan and stop it

Quick script to move all the slots of web apps in a subscription to a new app service plan and stop them. To save resources I keep our development slots stopped in our production apps. I keep them on a lower much less expensive app service plan as well. But with all the deployments we forget and I have to move things around.

Script below will move all the slots named $slotname to the app service plan $AppPlanMoveTo and stop them.

$rg = "ResourceGroupName"
$AppPlanMoveTo = "Name of the app plan moving to"
$slotname = "name of the slot, eg staging"
$apps = Get-AzureRmWebApp
$appnames = ($apps).Name
ForEach ($appname in $appnames) {
Set-AzureRmWebAppSlot -Name "$appname" -Slot $slotname -ResourceGroupName $rg -AppServicePlan $AppPlanMoveTo
Stop-AzureRmWebAppSlot -ResourceGroupName $rg -Name "$appname" -Slot $slotname
}

Leave a Comment

Your email address will not be published.

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