Upload VHD to Azure

Khanick 1 Reputation point
2020-01-07T17:39:51.983+00:00

Hello,

I have a VM created on Hyper-V, the file is vhd, i would like to load this vhd to Azure. I found couples articles on internet about uploading VHD to Azure, but they were saturated too many details and took to different links.
Has anyone successful done this task? Any good advice, links can be shared?

Thank you in advance.

Nick

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,118 questions
{count} votes

2 answers

Sort by: Most helpful
  1. KarishmaTiwari-MSFT 18,367 Reputation points Microsoft Employee
    2020-01-07T22:14:20.673+00:00

    Hello,

    Please refer to the following document on Uploading VHD to Azure and let me know if you have any questions:

    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/prepare-for-upload-vhd-image

    0 comments No comments

  2. Dave Rendon 21 Reputation points MVP
    2020-03-31T20:54:34.51+00:00

    Here´s a quick script to move your vhd and provision the VM

    1. Create a resource group
    2. Execute: Connect-AzAccount
    3. Run the script - modify the parameters as needed

    Source: https://github.com/daveRendon/Moving-VHD-to-Azure-with-PowerShell-and-create-VM-image/blob/master/src/moving-vhd-to-Azure-create-vm-image.ps1

    $subscriptionName = "Your Subscription Name"
    $subscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    $tenantId ="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    $resourceGroupName = 'DRendon'
    $location = 'EastUS'
    $vhdName = 'kemp360central-v1.25.vhd'
    $imageName = 'kempcentral25'
    $containerName = "kempcentraldrtestcontainer"
    $storageAccountName = "kempcentraldrtest"
    
    Select-AzureRmSubscription -SubscriptionId $subscriptionId
    
    : #Select your default subscription on ARM
    
    Get-AzureRmSubscription -SubscriptionId $subscriptionId -TenantId $tenantId | Set-AzureRmContext
    
    [//]: # create new storage account
    
    $storageAccount = New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -SkuName Standard_LRS -Location $location
    $ctx = $storageAccount.Context
    
    [//]: # create container
    
    new-azurestoragecontainer -Name $containerName -Context $ctx -Permission blob
    
    [//]: # set the local path from the vhd
    $localPath = 'C:\Users\daver\Downloads\kemp360central\kemp360central-v1.25.vhd'
    
    
    [//]: # set the url of the image and move the vhd, also use the -overwrite option since process might fail sporadically
    [//]: # -overwrite solves the error Add-AzureRmVhd : The pipeline was not run because a pipeline is already running.
    [//]: # Pipelines cannot be run concurrently
    $urlOfUploadedImageVhd = ('https://' + $storageAccountName + '.blob.core.windows.net/' + $containerName  + '/' + $vhdName)
    Add-AzureRmVhd -ResourceGroupName $resourceGroupName -Destination $urlOfUploadedImageVhd `
    -LocalFilePath $localPath -OverWrite
    
    [//]: # Create a managed image from the uploaded VHD
    $imageConfig = New-AzureRmImageConfig -Location $location
    
    [//]: # set the managed disk from the image
    $imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsType Windows -OsState Generalized `
        -BlobUri $urlOfUploadedImageVhd
    
    $image = New-AzureRmImage -ImageName $imageName -ResourceGroupName $resourceGroupName -Image $imageConfig
    
    0 comments No comments