One story of converting classic VM (ASM) to Azure Resource Model (ARM)

Microsoft Azure’s classic side is dead. Perioid. If you try to access it at , you’ll get immediate redirect to ARM at

I just happens that there are tons of classic VM’s laying around. Working perfectly. But. But Microsoft announced they should be converted to Azure Resource Model, or ARM, or Portal, or The New One. Why? Because the old one, the classic, or the ASM, doesn’t support the new features. And those features keeps coming.

So, now it’s the time to convert your classic VM’s, and their sub-services, to ARM. If you connect with Azure’s support, they will redirect you, after few steps, to You’ll manage following this document, but it is far from perfect. You’ll hit barriers like VNet.

I hit my head on the wall hard. I Google’d, YouTube’d, StackOverFlow’d, ExpertExchange’d, and Colleague’d. And found the answer. OK, I admit it isn’t 100% definitive and full-proof, but it is close. It is a series of copied and modified scripts. But it gets the job done, if you understand the principals and have read the documents about the subject itself.

I’ll update the post while I encounter different scenarios in the whole process, but here goes version 1.0:

$oldSub = "oldSubscriptionName" #Change this to the subscription you are working with
$cred = Get-Credential #Inserted credentials should be "Owner" AND "Co-Administrator" in both subscriptions

Login-AzureRmAccount -Credential $cred
Select-AzureRmSubscription -SubscriptionName $oldSub

Add-AzureAccount -Credential $cred
Select-AzureSubscription -SubscriptionName $oldSub

#Migrate to ARM
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate
Get-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate

Get-AzureVnetSite | Select -Property Name #Pick a correct VNet and insert it below to "vnetName"
$vnetName = "vnetName"
Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $vnetName -Verbose

#If you need to abort, below is the code to it
#Move-AzureVirtualNetwork -Abort -VirtualNetworkName $vnetName

Move-AzureVirtualNetwork -Commit -VirtualNetworkName $vnetName

#You need the StorageAccountName, which can be found at Azure Portal
$storageAccountName = "storageAccountName"
Move-AzureStorageAccount -Prepare -StorageAccountName $storageAccountName

#If you need to abort, below is the code to it
#Move-AzureStorageAccount -Abort -StorageAccountName $storageAccountName

Move-AzureStorageAccount -Commit -StorageAccountName $storageAccountName

#Move all resources to same RG
$sourceRG = "rgName-Migrated" #Change this to the one that popped up as a new one in Portal
$destRG = "destinationRGName" #Change this to final name you want the Resource Group to be
$resources = Find-AzureRmResource -ResourceGroupNameContains $sourceRg | ? {$_.ResourceType -ne "Microsoft.Compute/virtualMachines/extensions"} #VM Extensions are not top level resources, so can't be moved this way, but follows the VM
Move-AzureRmResource -DestinationResourceGroupName $destRG -ResourceId $resources.ResourceID
Remove-AzureRmResourceGroup $sourceRG

#Remove Key Vault link
$vmName = "vmName" #Change this to VM name worked
$vm = Get-AzureRmVM -ResourceGroupName $destRG -Name $vmName
$vm.OSProfile.Secrets = New-Object -TypeName "System.Collections.Generic.List[Microsoft.Azure.Management.Compute.Models.VaultSecretGroup]"
Update-AzureRmVM -ResourceGroupName $destRG -VM $vm -Debug

#Move subscription
$newSub = "newSubscriptionName" #Change this to subsriction you want the RG to reside
$newRG = "newRGName" "Change this to name you want the services reside in the new subscription
$location = "North Europe" #Change this to location you want the services to be
$subscriptionID = Get-AzureRmSubscription -SubscriptionName $newSub
$resources = Find-AzureRmResource -ResourceGroupNameContains $destRg| ? {$_.ResourceType -ne "Microsoft.Compute/virtualMachines/extensions"}
Select-AzureRmSubscription -SubscriptionName $newSub
if (!(Get-AzureRmResourceGroup -Name $newRG -ErrorAction SilentlyContinue)) {
New-AzureRmResourceGroup -Name $newRG -Location $location
Select-AzureRmSubscription -SubscriptionName $oldSub
Move-AzureRmResource -DestinationResourceGroupName $newRG -ResourceId $resources.ResourceID -DestinationSubscriptionId $subscriptionID.SubscriptionId

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *