Migrating Web Apps to Azure at Scale with PowerShell

Assumptions and preliminary steps

You have created an Azure Migrate project, web apps conform to the requirements, you have downloaded the PowerShell scripts and have an Azure role with sufficient permissions to create the respective resources. 

Sequence of Steps

.\Get-SiteReadiness.ps1

Discovers the sites on the server where you run it and determines which ones are suitable for migration. 

Here is what output could look like when migration is likely to fail:

[INFO] Report generated for somesite.domain.com 
[WARN] Warnings for somesite.domain.com : FrameworkCheck,HttpsBindingCheck,TcpPortCheck
[WARN] Failed Checks for somesite.domain.com  : AuthCheck,ProtocolCheck,AppPoolIdentityCheck,LocationTagCheck,ContentSizeCheck
[WARN] FATAL errors detected in somesite.domain.com : ContentSizeCheck,
[WARN] These failures prevent migration using this tooling. You will not be able to migrate this site until the checks resulting in fatal errors are fixed

..and an example of a site that can be migrated:

[INFO] Report generated for site1.somedomain.com
[WARN] Warnings for site1.somedomain.com: FrameworkCheck,HttpsBindingCheck
[INFO] site1.somedomain.com: No Blocking issues found and the site is ready for migration to Azure!>

[INFO] Readiness checks complete. Readiness results outputted to ReadinessResults.json

.\Get-SitePackage.ps1

Uses the ReadinessResults.json file produced in the previous step to package the sites. By default it packages only the sites that have no failures in the previous step but if you feel brave enough and know what you are doing, you can override this with the -MigrateSitesWithIssues switch.

.\Generate-MigrationSettings.ps1

Takes all the packaged sites and spreads them out over app service plans in the specified region and subscription. The file is also used as input by the next script.

It is likely that you may need to edit this file to adjust app service plan to your liking, as well as to address errors related to site naming to resolve errors like the ones below: 

[ERROR] AzureSiteName 'somesitename.site.com' Invalid. Site names only allow alphanumeric characters and hyphens, cannot start or end in a hyphen, and must be less than 64 chars.

[ERROR] AzureSiteName 'somesitename.site.com' AlreadyExists. Hostname 'somesitename.site.com' already exists. Please select a different name.

[ERROR] Certain Azure site names in C:\Users\Public\Downloads\AppServiceMigrationScripts\MigrationSettings.json are not available on Azure cloud

After you remediate any issues, a successful run will result in the following:

Supply values for the following parameters:
SitePackageResultsPath: C:\Users\public\Downloads\AppServiceMigrationScripts\OutDir\packs\PackageResults.json
Region: southcentralus
SubscriptionId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ResourceGroup: rg-webapp
[INFO] Setting Default Tier as PremiumV3
[INFO] Migration settings have been successfully created and written to MigrationSettings.json

.\Invoke-SiteMigration.ps1

If all goes well, after you execute, you will see output similar to this:

Supply values for the following parameters:
MigrationSettingsFilePath: C:\Users\public\Downloads\AppServiceMigrationScripts\MigrationSettings.json
[INFO] Creating App Service Plan 'Migration_ASP_20230627_847501'
[INFO] Azure subscription has been set to xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (Name: Personal Az)
[INFO] Resource Group rg-webapp found in southcentralus
[INFO] Creating App Service Plan Migration_ASP_20230627_847501 ....
[INFO] App Service Plan Migration_ASP_20230627_847501 has been created in resource group rg-webapp
[INFO] Migrating site 'site1' to Azure....
[INFO] Created Web App site1 for the site 'site1'
[INFO] Configuring Azure settings for Azure site
[INFO] Configuring any virtual directories...
[INFO] Virtual directories/applications have been configured on Azure for site1
[INFO] Beginning zip deployment...
[INFO] Succesfully migrated site 'site1' to https://site1.azurewebsites.net

[INFO] Resources created during migration
[INFO]
ResourceName                  ResourceType     Created Error
------------                  ------------     ------- -----
Migration_ASP_20230627_847501 App Service Plan    True
site1                Site                True
You should also read:

Azure Key Vault Pt.1

As you learn to use IaC and Terraform, it is natural to progress from initially supplying credentials for a resource in the main.tf…

Azure Hybrid Connect

Background: The organization I work for needed to move over 100 internally hosted apps to Azure's web app hosting functionality due to soon-to-be…