Moving VM image defention from one computer gallery to different computer gallery

sns 9,236 Reputation points
2023-09-26T07:09:44.1+00:00

I would like to move image from one VM image definition in computer gallery to another VM image definition in computer gallery.

Here source and destination of computer gallery are from different subscription.

Please suggest if there is any PowerShell command for this.

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

2 answers

Sort by: Most helpful
  1. Tech-Hyd-1989 5,796 Reputation points
    2023-09-26T09:32:23.7666667+00:00

    Hello sns

    There is a PowerShell command to move an image from one VM image definition in a computer gallery to another VM image definition in a computer gallery in a different subscription. The command is called Export-AzureComputeGalleryImageVersion and Import-AzureComputeGalleryImageVersion.

    To use the commands, you will need to have the following:

    • The Azure PowerShell module installed.
    • The subscription ID of the source and destination subscriptions.
    • The name of the source and destination computer galleries.
    • The name of the source and destination VM image definitions.

    Here are the steps on how to move an image from one VM image definition in a computer gallery to another VM image definition in a computer gallery in a different subscription using PowerShell:

    1. Export the image from the source VM image definition:

    PowerShell

    Export-AzureComputeGalleryImageVersion -SubscriptionId <source_subscription_id> -ComputerGalleryName <source_computer_gallery_name> -ImageDefinitionName <source_image_definition_name> -Version <source_image_version> -OutputFile <output_file_path>
    

    Use code with caution. Learn more

    content_copy

    1. Import the image to the destination VM image definition:

    PowerShell

    Import-AzureComputeGalleryImageVersion -SubscriptionId <destination_subscription_id> -ComputerGalleryName <destination_computer_gallery_name> -ImageDefinitionName <destination_image_definition_name> -InputFile <input_file_path>
    

    Use code with caution. Learn more

    content_copy

    Here is an example of how to use the commands:

    PowerShell

    # Export the image from the source VM image definition
    Export-AzureComputeGalleryImageVersion -SubscriptionId <source_subscription_id> -ComputerGalleryName <source_computer_gallery_name> -ImageDefinitionName <source_image_definition_name> -Version <source_image_version> -OutputFile C:\Temp\image.vhd
    
    # Import the image to the destination VM image definition
    Import-AzureComputeGalleryImageVersion -SubscriptionId <destination_subscription_id> -ComputerGalleryName <destination_computer_gallery_name> -ImageDefinitionName <destination_image_definition_name> -InputFile C:\Temp\image.vhd
    

    Use code with caution. Learn more

    content_copy

    Once the image has been imported to the destination VM image definition, you can deploy a virtual machine from the image.

    I hope this helps! Let me know if you have any other questions.


  2. Mehmet Dülger 5 Reputation points
    2024-10-04T09:26:52.6866667+00:00

    Anyone who is searching for this here is the link to the documentation:

    https://learn.microsoft.com/en-us/azure/virtual-machines/image-version?tabs=portal%2Ccli2#create-an-image-in-one-tenant-using-the-source-image-in-another-tenant

    The documentation is speaking from moving one VM Image from tenant/subscription to another tenant/subscription but you can also use it to move a VM image inside the the same subscription.

    Please be aware that the region for replication is the same between the source and target images. Also check that the image definitions have the same value for the VM generation and need to support the same security type.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.