How to Rebuild from an Existing Managed Disk

If Azure PowerShell is not installed, please install it from then modify and run the following script:

# To login to Azure Resource Manager

# To view all subscriptions for your account

# To select a default subscription for your current session
Get-AzureRmSubscription –SubscriptionID ‘SUBSCRIPTONID’ | Select-AzureRmSubscription

#Fill in all variables
$loc = “LOCATION”;
$vmSize = “SIZE”;
$nicName = “NIC NAME”;
#$avName = “AV SET NAME”;
$osDiskName = “OS DISK NAME”;
$osDiskResouceId = “OS DISK RESOURCE ID”;
#$dataDiskName = “DATA DISK NAME”;
#$dataDiskResourceId = “DATA DISK RESOURCE ID”;

#Comment/uncomment based on feature needs

#No AV Set
$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize;
#AV Set
#$avSet = Get-AzureRmAvailabilitySet –Name $avName –ResourceGroupName $rgName;
#$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize -AvailabilitySetId $avSet.Id;

#Get NIC Resource Id and add
$nic = Get-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName;
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id;

#Windows VM
$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDiskResouceId -name $osDiskName -CreateOption Attach -Windows;

#Linux VM
#$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDiskResouceId -name $osDiskName -CreateOption Attach -Linux;

#Data Disks – optional
#Add-AzureRmVMDataDisk -VM $vm -ManagedDiskId $dataDiskResourceId -Name $dataDiskName -Caching None -DiskSizeInGB 1023 -Lun 0 -CreateOption Attach;

New-AzureRmVM -ResourceGroupName $rgName -Location $loc -VM $vm;


  1. Hi Micah,
    Thanks for posting this one. I see you have enhanced this script then the one on Microsoft technet. In the meanwhile I used the original one as reference and output was to one above you have now.

    Great! I am now able to execute my vNet migration.

    1. Hi Ivan,
      Glad you were able to get some use out of it :). I am working on updating parts of the site still. If you ever notice anything out of date just let me know and I will make sure to move that to the top of my list!

Leave a Reply

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