I was trying to consolidate "app service plans" and wanted to migrate one "app service" to an existing "app service plan". The "app service" was originally labelled with the incorrect "resource group" so this was changed first from the azure portal. I also changed the resource group of the source "app service plan" to match the target "resource group" of the "app service plan" using the Azure portal. I then tried to change the "app services' " "app service plan" but the Azure portal failed with I then changed the source resource group of the "app service plan" to the target and the Azure Portal warns "App service plan name must be unique in each resource group." The error is correct in that I am trying to move to an existing "app service plan". I then went to azure cli and ran
Set-AzWebApp -ResourceGroupName "Prod_AppServices" -Name "websiteName" -AppServicePlan "AppServicePlanProd"
where I have replaced the real web site name with "websiteName". This command failed with
Set-AzWebApp : Operation returned an invalid status code 'Conflict'
At line:1 char:1
ChatGPT then suggested that I run the following to make sure I meet the requirements of moving an app from one "app service plan" to aonther in that the resource groups, regions and pricing tier familes are the same :
Variables
$rgName = "Prod_AppServices"
$appName = "appName"
$targetPlanName = "AppServicePlanProd"
Get the web app and its current plan
$app = Get-AzWebApp -ResourceGroupName $rgName -Name $appName
$currentPlan = Get-AzAppServicePlan -ResourceGroupName $rgName -Name $app.ServerFarmId.Split("/")[-1]
Get target plan
$targetPlan = Get-AzAppServicePlan -ResourceGroupName $rgName -Name $targetPlanName
Write-Host "=== Current Plan ==="
Write-Host "Name: $($currentPlan.Name)"
Write-Host "Location: $($currentPlan.Location)"
Write-Host "OS: $($currentPlan.Reserved -replace 'True','Linux' -replace 'False','Windows')"
Write-Host "SKU: $($currentPlan.Sku.Name)"
Write-Host ""
Write-Host "=== Target Plan ==="
Write-Host "Name: $($targetPlan.Name)"
Write-Host "Location: $($targetPlan.Location)"
Write-Host "OS: $($targetPlan.Reserved -replace 'True','Linux' -replace 'False','Windows')"
Write-Host "SKU: $($targetPlan.Sku.Name)"
Write-Host ""
Compatibility checks
$compatible = $true
if ($currentPlan.Location -ne $targetPlan.Location) {
Write-Host "❌ Region mismatch: $($currentPlan.Location) vs $($targetPlan.Location)"
$compatible = $false
} else {
Write-Host "✔ Regions match"
}
if ($currentPlan.Reserved -ne $targetPlan.Reserved) {
Write-Host "❌ OS mismatch: $($currentPlan.Reserved -replace 'True','Linux' -replace 'False','Windows') vs $($targetPlan.Reserved -replace 'True','Linux' -replace 'False','Windows')"
$compatible = $false
} else {
Write-Host "✔ OS types match"
}
if ($currentPlan.Sku.Family -ne $targetPlan.Sku.Family) {
Write-Host "❌ Pricing tier family mismatch: $($currentPlan.Sku.Family) vs $($targetPlan.Sku.Family)"
$compatible = $false
} else {
Write-Host "✔ Pricing tier family matches"
}
if ($compatible) {
Write-Host "`n✅ The target plan is compatible. You can proceed with the move."
} else {
Write-Host "`n⚠ Plans are NOT compatible. You must align OS, region, and tier family before moving."
}
where I have replaced the real appName. The Azure cli from powershell returned the following:
=== Current Plan ===
Name: AppServicePlanDev
Location: East US 2
OS: Windows
SKU: P1v2
=== Target Plan ===
Name: AppServicePlanProd
Location: East US 2
OS: Windows
SKU: P1v2
✔ Regions match
✔ OS types match
✔ Pricing tier family matches
✅ The target plan is compatible. You can proceed with the move.
ChatGPT then suggested running:
$targetPlan = Get-AzAppServicePlan -ResourceGroupName "Prod_AppServices" -Name "AppServicePlanProd"
Update the Web App's serverFarmId
Set-AzResource -ResourceGroupName "Prod_AppServices" `
-ResourceType "Microsoft.Web/sites" `
-ResourceName "resourceName" `
-Properties @{ serverFarmId = $targetPlan.Id } `
-ApiVersion 2022-09-01 `
-Force
Set-AzResource : {"Code":"Conflict","Message":"Cannot change the site resourceName to the App Service Plan AppServicePlanProd due to hosting constraints.","Target":null,"Details":[{"Message":"Cannot change the site creyield-ai to the App Service Plan AppServicePlanProd
due to hosting constraints."},{"Code":"Conflict"},{"ErrorEntity":{"ExtendedCode":"59602","MessageTemplate":"Cannot change the site {0} to the App Service Plan {1} due to hosting
constraints.","Parameters":["creyield-ai","AppServicePlanProd"],"Code":"Conflict","Message":"Cannot change the site resourceName to the App Service Plan AppServicePlanProd due to hosting constraints."}}],"Innererror":null}
CorrelationId: ecbb19d0-1e33-4c41-966f-515c4f288e22
At line:5 char:1
The azure portal then suggested that I remove any certifcates associated with the "app service". When I tried to remove the certificates I received the following error:
To delete this certificate, first delete the binding it's used in. ChatGPT suggested the following:
Remove-AzWebAppSSLBinding -ResourceGroupName "Prod_Website" -WebAppName "webAppName" -Name "name" -DeleteCertificate $False
Confirm
Are you sure you want to remove the web app ssl binding for hostname 'creyield.ai'
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
Remove-AzWebAppSSLBinding : Operation returned an invalid status code 'NotFound'
At line:1 char:1
- Remove-AzWebAppSSLBinding -ResourceGroupName "Prod_Website" -WebAppNa ...
-
+ CategoryInfo : NotSpecified: (:) [Remove-AzWebAppSSLBinding], DefaultErrorResponseException
+ FullyQualifiedErrorId : Microsoft.Azure.Management.WebSites.Models.DefaultErrorResponseException,Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.RemoveAzureWebAppSSLBinding
where I have replaced the real WebAppName and Name with webAppName and name