VM Migration from Azure to AWS: A Step-by-Step Guide
VM migration is a critical task when moving workloads across cloud platforms like Azure and AWS. Whether you’re shifting a Windows VM from Azure to AWS, or handling large-scale migrations, knowing the right steps can streamline the entire process. In this guide, we’ll walk through the essential steps for migrating a Windows VM from Azure to AWS using PowerShell, providing a clear path to complete the migration efficiently.

Prerequisites for VM Migration from Azure to AWS
Before diving into the migration process, make sure you have the following prerequisites:
- Azure and AWS Accounts: Create accounts for both platforms.
- Azure Storage Account: Needed to temporarily store VM images.
- Windows VM in Azure: Have an active VM in Azure that you want to migrate.
- AWS S3 Bucket: Set up an S3 bucket in AWS for storing the VM image.
Why Use PowerShell for VM Migration?
PowerShell offers a streamlined and efficient way to handle VM migration. Instead of relying on slow internet connections, PowerShell allows you to transfer large virtual disk files directly between Azure and AWS, utilizing cloud infrastructure for faster data transfer.
Step 1: Prepare the Azure VM for Migration
To begin the VM migration process, the Azure VM needs to be generalized to remove machine-specific settings. This step ensures the VM can be successfully imported into AWS.
- Run Sysprep: This tool generalizes the VM by stripping out machine-specific configurations.
C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe - Shutdown the VM: After running Sysprep, the VM will automatically shut down. Make sure to power off the VM completely for the migration.
Get-AzureRmVM -ResourceGroupName adbtesting -Name PSWA | Stop-AzureRmVm -Force
Once your VM is generalized and shut down, it is ready for the next step in the migration.
Step 2: Set Up Azure File Share for VM Migration
Since large VM disk files need to be transferred, using Azure Files is an excellent option for temporary storage. Here’s how you can configure it:
- Create an Azure File Share: This will serve as the temporary storage for the VHD file.
$storageAccount = Get-AzureRmStorageAccount -ResourceGroupName adbtesting -Name adbtestingdisks656 $storageKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.StorageAccountName | select -first 1).Value $storageContext = New-AzureStorageContext -StorageAccountName $storageAccount.StorageAccountName -StorageAccountKey $storageKey $share = New-AzureStorageShare -Name migrationstorage -Context $storageContext - Mount the Share as a Drive: This allows the Azure File Share to be accessible for file transfers.
$secKey = ConvertTo-SecureString -String $storageKey -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential -ArgumentList "Azure\$($storageAccount.StorageAccountName)", $secKey $shareDrive = New-PSDrive -Name X -PSProvider FileSystem -Root "\\$($storageAccount.StorageAccountName).file.core.windows.net\$($share.Name)" -Credential $credential -Persist
Step 3: Configure AWS for VM Migration
Before transferring the VM image to AWS, configure the VM Import/Export service. This service allows you to import your Azure VM as an AWS image.
- Create IAM Roles and Policies: These permissions will allow AWS to manage the imported image.
- Service Role (servicerole.json):
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "vmie.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "sts:Externalid": "vmimport" } } } ] } - Policy (policy.json):
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetBucketLocation", "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::disk-image-file-bucket", "arn:aws:s3:::disk-image-file-bucket/*" ] }, { "Effect": "Allow", "Action": [ "ec2:ModifySnapshotAttribute", "ec2:CopySnapshot", "ec2:RegisterImage", "ec2:Describe*" ], "Resource": "*" } ] }
- Service Role (servicerole.json):
- Upload JSON Files to Azure: Once the JSON files are ready, upload them to the Azure File Share to allow AWS to assign roles and policies.
Step 4: Transfer the VM Disk Image to AWS
With the roles set up, it’s time to move the VM disk image from Azure to AWS.
- Identify the Azure VM’s VHD URI: Use PowerShell to retrieve the URI of the VM’s VHD file.
$vm = Get-AzureRmVM -Name PSWA -ResourceGroupName ADBTESTING $vhdUri = $vm.StorageProfile.OsDisk.Vhd.Uri - Download the VHD to Azure File Share: This step transfers the VHD file to the temporary storage.
Save-AzureRmVhd -ResourceGroupName $vm.ResourceGroupName -SourceUri $vhdUri -LocalFilePath $localVhdPath -NumberOfThreads 32 - Upload VHD to AWS S3 Bucket: Transfer the downloaded VHD to your AWS S3 bucket using multipart upload for efficiency.
Write-S3Object -BucketName adambbucket -File $localVhdPath -Key pswa.vhd
Step 5: Convert the VHD into an AWS AMI
Once the VHD is uploaded to AWS, it’s time to convert it into an Amazon Machine Image (AMI).
- Import the VHD as an AMI: Use the following PowerShell script to initiate the import process.
$container = New-Object Amazon.EC2.Model.ImageDiskContainer $container.Format = 'VHD' $container.UserBucket = New-Object Amazon.EC2.Model.UserBucket $container.UserBucket.S3Bucket = 'adambbucket' $container.UserBucket.S3Key = 'pswa.vhd' $params = @{ ClientToken = 'idempotencyToken'; Platform = 'Windows'; LicenseType = 'AWS'; DiskContainer = $container } $task = Import-EC2Image @params - Monitor the Import Task: Check the status of the import process using the following command:
Get-EC2ImportImageTask -ImportTaskId $task.ImportTaskId
Step 6: Clean Up After VM Migration
Once the VM migration is complete, you can clean up any temporary resources created during the process.
- Remove the Azure File Share: Delete the file share used for temporary storage.
Remove-AzureStorageShare -Name migrationstorage -Context $storageContext
Conclusion
VM migration is an essential skill for moving workloads between Azure and AWS. By following these steps, you can efficiently migrate a Windows VM using PowerShell while minimizing manual intervention. For ongoing support with cloud migration and managed services, ZippyOPS specializes in DevOps, Cloud infrastructure, and Automated Operations. Reach out to us at sales@zippyops.com for more information.



