How can I get the URL of a captured VM Image store

2019-07-30 02:41发布

问题:

I am trying to create a new VM in Azure RM based on the sysprepped capture of an existing VM installation. That is:

$urlOfCapturedImage = <I cannot find this>

...

$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $newOsDiskUri `
        -CreateOption fromImage -SourceImageUri $urlOfCapturedImage -Windows

New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location -VM $vm

My current problem is finding the correct URL for the stored VM image, since it doesn't appear to be stored as a VHD blob in my storage account. Instead, I find it in the Images category, with the following, limited information:

I have tried using the following URL/URIs, but none of them work:

https://<storage-account-name>.blob.core.windows.net/system/Microsoft.Compute/Images/jira-7-sysprep-20170724133831.vhd

/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Compute/images/jira-7-sysprep-20170724133831

Does anyone know how to get the proper URL for my VM image? Or could it simply be that I am using the wrong method altogether?

回答1:

Does anyone know how to get the proper URL for my VM image?

For a Azure VM image, the VHD is managed by Azure, you could not get the URL.

Your command is used for create VM from storage account. If you want to create VM from image, you could use the following command to create a VM from custom image.

$image = Get-AzureRmImage `
    -ImageName myImage `
    -ResourceGroupName myResourceGroupImages

# Here is where we specify that we want to create the VM from and image and provide the image ID
$vmConfig = Set-AzureRmVMSourceImage -VM $vmConfig -Id $image.Id

$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id

New-AzureRmVM `
    -ResourceGroupName myResourceGroupFromImage `
    -Location EastUS `
    -VM $vmConfig

More information about this please refer to this link.