How to Create a Custom Virtual Machine Image on Microsoft Azure

I'm a cloud and DevOps upskilling candidate focused on building practical skills through real-world AWS projects. I enjoy getting hands-on with core services like EC2, EBS, S3, and IAM, and documenting my learning journey through blog posts and GitHub repositories. Every project I complete is a step toward mastering cloud fundamentals and developing automation skills that align with DevOps practices. My goal is to grow into a confident, capable engineer who can design and manage scalable infrastructure. GitHub: https://github.com/abhishek-balaji-2025
Creating virtual machines repeatedly from scratch can be time-consuming and error-prone. Whether you're setting up dev environments, deploying apps, or configuring security tools, having a custom image on Microsoft Azure can save you hours of work. In this guide, you'll learn how to capture a fully configured VM as a reusable image — ready to launch anytime with your preferred setup.
What You Will Learn in This Blog
By the end of this guide, you’ll know how to:
✅ Prepare and configure a VM for image creation
✅ Deprovision a VM safely using Azure tools
✅ Capture a custom image from an existing VM
✅ Deploy new VMs from your custom image
✅ (Bonus) Use Shared Image Gallery for scaling and versioning

After logging into your Microsoft Azure account, navigate to the top search bar and enter “Resource groups.” From the results, select Resource groups to proceed. We’ll begin by creating a new resource group, which will serve as a logical container for managing and organizing related Azure resources.


On the top left-hand corner of the Resource Groups page, you will see a “Create” button. Click on it to initiate the process of creating a new resource group.

On the Create Resource Group page:
Select your subscription from the dropdown menu.
Enter a name for your resource group. Choose a name that clearly represents the resources it will contain.
Under Region, select Central India as the location for your resource group.

Click on “Next: Tags >” to proceed to the Tags section. Here, you can assign key-value pairs to your Azure resources, which helps with organization, cost management, and resource identification. While tags are optional, they are highly recommended for environments with multiple resources to ensure clarity and better governance.

Click on the “Next: Review + Create >” button to view a summary of your resource group configuration. This section allows you to verify all the details you’ve provided. If everything looks correct and meets your requirements, proceed by clicking on the “Create” button to finalize and deploy the resource group.

Once the resource group is successfully created, you will see a confirmation message appear under the notification icon (bell icon) in the top-right corner of the Azure portal. This message confirms that your resource group has been provisioned and is now ready for use. You can click on the notification to quickly navigate to the newly created resource group.


Now that the resource group is successfully created, let’s proceed to create a virtual machine—this will act as the parent VM, from which we will later capture a custom image.
Steps to Create the Parent Virtual Machine:
Go to the search bar at the top of the Azure portal and type “Virtual machines”.
Select Virtual machines from the search results.
On the Virtual Machines page, click the “Create” button, then select “Azure virtual machine”.


On the Virtual Machines page, click on the “+ Create” button at the top left corner. From the dropdown options, select “Virtual machine” to begin configuring your parent VM—the base instance that will later be used to create your custom image.


On the Basics tab of the Virtual Machine creation page:
Subscription: Select your active Azure subscription.
Resource Group: Choose the resource group you just created.
Virtual Machine Name: Enter a clear and descriptive name for your parent virtual machine (e.g.,
ParentVM-CustomImage).Region: Select Central India as the deployment region. (You can choose a different region based on your preference or compliance requirements.)
Availability Options: Set this to No infrastructure redundancy required for this demonstration.


Under the Image section:
Click on “See all images” to browse available OS images.
In the search bar, type “Windows Server 2019” and press Enter.
From the results, select:
[smalldisk] Windows Server 2019 Datacenter - x64 Gen2Click “Select” to confirm your image selection.
This version provides a stable environment ideal for creating a base image, while also offering broad compatibility with enterprise workloads.

Under the Size section:
Click on “See all sizes” to view the available virtual machine configurations.
In the search bar, type “B2ms” and press Enter.
Select Standard B2ms — this VM size includes 2 vCPUs and 8 GB of RAM, offering a good balance between performance and cost for image preparation.
Click “Select” to apply the size to your virtual machine configuration.

Under the Administrator Account section:
Username: Enter a secure and recognizable admin username (e.g.,
azureadmin).Password: Create a strong password that meets Azure’s complexity requirements.
Confirm Password: Re-enter the same password for confirmation.
Under the Inbound Port Rules section:
Set Public inbound ports to Allow selected ports.
From the dropdown, select:
RDP (3389) – for remote desktop access
HTTP (80) – to allow web traffic if needed
These settings ensure that you can connect to the VM via Remote Desktop and serve web content during configuration, if applicable.


Under the Disks tab:
- For the OS disk type, select Standard SSD. This option provides a good balance between performance and cost, making it ideal for demonstration or testing purposes.
💡 Note: If you are provisioning a VM for live production environments or hosting mission-critical applications, it’s recommended to choose Premium SSD for higher performance and lower latency.
Under the Data Disks section:
You have the option to attach additional data disks to your virtual machine if you need extra storage for applications, logs, or databases.
However, for this demonstration, attaching a data disk is not required. You can proceed without adding any data disks by simply clicking “Next: Networking >”.





For the Networking, Management, Monitoring, Advanced, and Tags sections, we will proceed with the default configurations provided by Azure. These defaults are suitable for this demonstration and will allow us to focus on the core objective: capturing a custom image from our parent virtual machine.
Click “Review + Create” to proceed.


Once validation is complete and marked as “Passed”, you’ll see a summary of your VM configuration. Review all the settings to ensure they are correct.
Then, click on “Create” to begin provisioning your virtual machine. Azure will start deploying the resources, and you can monitor the progress via the Notifications (bell icon) at the top-right corner of the portal.



Once the VM has been successfully deployed and sysprepped, return to the Azure Portal and click the “Go to resource” button. This will take you directly to the Virtual Machine overview page, where you can begin the process of capturing the custom image.

On your local Windows machine:
Press Windows Key + R to open the Run dialog.
Type the following command:
mstsc /v:<your-public-IP-address>Replace
<your-public-IP-address>with the public IP of your Azure VM (available on the VM overview page in Azure).Press Enter. This will launch Remote Desktop Connection and initiate a session with your virtual machine.
When prompted, enter the username and password you created earlier during VM setup.
You will now be connected to the VM and can proceed with installation and customization.


Enter the username and password you configured during the virtual machine setup, then click OK or press Enter to initiate the Remote Desktop session.
⚠️ If you receive a certificate warning, you can safely click Yes to continue the connection for this demonstration.

After entering your username and password, a security warning may appear indicating that the remote connection's certificate cannot be verified.
Click on the “Yes” button to proceed with the Remote Desktop session. This will log you into your Azure virtual machine, where you can begin setting up the environment for your custom image.



Install IIS Web Server
In Server Manager, go to the top-right corner and click “Manage”.
From the dropdown, select “Add Roles and Features.”
In the Add Roles and Features Wizard:
Click Next until you reach the Server Roles section.
Check the box for Web Server (IIS).
Click Add Features when prompted.
Click Next through the remaining steps.
On the Confirmation page, click Install.
Wait for the installation to complete, then click Close.





Final Step: Generalize the VM Using Sysprep
Before capturing the image, you need to generalize the VM to remove machine-specific information:
Press Windows + R to open the Run dialog.
Type
sysprepand hit Enter.In the System Preparation Tool window:
Set System Cleanup Action to:
Enter System Out-of-Box Experience (OOBE)Check the box for Generalize
Set Shutdown Options to:
Shutdown
Click OK





Sysprep will now prepare the image and automatically shut down the VM.
Once that’s done, we’ll return to the Azure portal to capture this machine as a reusable custom image.

Capture the VM as a Custom Image
In the Azure portal, go to the Virtual Machines section.
Select your stopped parent VM.
At the top menu, click on “Capture”.
In the Create image page:
Provide a name for your image (e.g.,
Win2019-IIS-CustomImage)Choose the same resource group
Optionally, select the checkbox:
✅ “Automatically delete this virtual machine after creating the image”Choose “No” for the Shared Image Gallery (unless you want versioning and replication features)
Click “Review + create”, and then “Create” to generate your custom image.
Azure will now create a generalized image from your VM, which you can use to deploy identical VMs in the future — saving time and ensuring consistency across environments.


Configure Image Capture Settings
Resource Group: Select the same resource group you used for the parent VM (e.g.,
CustomImageRG).Image Name: Enter a meaningful name (e.g.,
Win2019-IIS-Image).Region: Ensure it matches the region of your parent VM (e.g., Central India).
Share Image to Azure Compute Gallery
Set Share image to Azure Compute Gallery to Yes.
Select “I would like to create an Azure Compute Gallery to store my custom images”.
Provide the following:
Gallery Name: e.g.,
MyCustomImageGalleryGallery Description: (Optional) e.g.,
Gallery for Windows Server custom VM imagesTarget Region: Leave as default or choose where you’d like replicas stored.
Click Next, review the summary, and then click “Create” to initiate the image creation process.
This will store your custom image in the newly created Azure Compute Gallery, making it reusable, versioned, and regionally replicated if needed.


Create Target VM Image Definition
Name: Enter a clear and descriptive name for the image definition (e.g.,
Win2019-IIS-Def).Publisher: Provide your organization or personal name (e.g.,
MyCompany).Offer: Define the purpose or product (e.g.,
WebServer).SKU: Specify a version or configuration type (e.g.,
IISv1).OS Type: Select Windows.
Hyper-V Generation: Choose Gen 2 (to match the parent VM).

Configure Image Version Details
Version number: Enter in the format
Major.Minor.Patch
Example:1.0.0End of life date (optional but recommended):
Set a future date when the image version should be considered obsolete.
Example:31-12-2026
💡 Tip: The version number helps with automation and version control. The end-of-life date is useful for governance and lifecycle management.

Set Default Storage SKU
Scroll to the Storage account type section.
Select Standard HDD (LRS) as the default SKU for this image version.
ℹ️ Standard HDD LRS is a cost-effective option ideal for general-purpose workloads, testing, or environments where performance isn't a critical factor.

Click on “Review + Create” to view a summary of all your configured settings—including image definition, version, storage type, and gallery information.
Carefully verify that all details are accurate. Once confirmed, click “Create” to begin publishing your custom image to the Azure Compute Gallery.
Azure will now start provisioning your image. Once completed, it will be available for deploying new virtual machines with your predefined configuration.





Once the image is successfully created, click on “Go to resource” to open the image overview page.
From here, users can easily create new virtual machines based on this custom image by clicking the “+ Create VM” button at the top. This allows you to deploy multiple identical VMs with your pre-installed software and configurations—saving time, improving consistency, and streamlining deployments.
Creating a Child VM from Custom Image
On the image resource page, click “+ Create VM”.
Fill in the basics just like before:
Select your subscription and resource group
Provide a name for the child VM (e.g.,
ChildVM-Web)Choose the same region as the image
Select the VM size, configure admin credentials, and choose inbound ports (e.g., RDP 3389, HTTP 80)
Proceed through the Disks, Networking, and other tabs
Click “Review + Create”, then Create
The child VM will be provisioned using your custom image, complete with IIS and any other configurations you set up in the parent VM—no need to redo the setup!
This is especially useful for scaling, automation, and maintaining consistency across environments.
Conclusion
Creating a custom image in Microsoft Azure is a powerful way to standardize and streamline your virtual machine deployments. By capturing a well-configured parent VM and storing it in an Azure Compute Gallery, you ensure consistency, save time on repetitive setup tasks, and improve overall scalability.
Whether you're building a development environment, deploying pre-configured workloads, or managing enterprise-grade infrastructure, custom images are essential for maintaining control and efficiency in the cloud.
Thank you for following along! If you found this guide helpful, feel free to share it or leave a comment below. For more tutorials on Azure and cloud automation, stay tuned to the blog.