Deploy an Azure VM from a generalized image in Azure RM portal

Posted by Romain Serre on August 2, 2016
Share on Facebook0Share on Google+0Share on LinkedIn9Share on Reddit1Tweet about this on Twitter0
5/5 (2)

Microsoft Azure provides a way to deploy Azure VM from the Marketplace or from a generalized image. When you deploy the Azure VM from the Marketplace, no customization is deployed. You have to configure the operating system as your master. When you have several Azure VMs to deploy, the customization of each system can be time consuming. A lot of companies have a master or a baseline image in a VMDK for VMWare, in a VHD(X) for Hyper-V or in a WIM image. In this topic we will see how to create a generalized image from a single Azure VM and how to deploy Azure VM from this generalized image.

In the old portal (, all steps can be done from the GUI but also by using PowerShell. In the new portal (, you have to use PowerShell because it is not yet integrated to the portal. In this topic, I will work from the new portal (AzureRM).


To follow this topic, you need some requirements:

  • I recommend you to install PowerShell v5 to import AzureRM PowerShell module
  • The AzureRM PowerShell module deployed (see below to install the module)
  • A deployed resource group
  • A deployed storage account from VM
  • A deployed virtual network with a subnet for VM
  • A deployed virtual machine to be generalized

If you have installed PowerShell v5, just run the following command to install the AzureRM module (in RunAs Administrator):

Install-Module AzureRM

In the below screenshot, you can see the deployed prerequisites in the TechCoffee resource group. The VM that will be generalized is called VM01.

Resource group

Make the customization and the sysprep

First of all, connect to the VM and make the customization. In my example, I create a folder c:\temp and I install .NET 3.5 feature:

Remote Desktop Connection

Once you have finished the customization, navigate to c:\windows\system32\sysprep and run sysprep.exe. Run the system preparation with the following settings:

Remote Desktop Connection

Export the sysprep VHD as template

Before running any PowerShell cmdlet on your Azure Subscription, you have to login and select the right Azure Subscription by using the following cmdlet:

First the VM must be stopped from the Azure perspective to be deallocated. The VM can be marked as generalized only on an Azure VM with deallocated state. When the below command will be executed, the VM state will be changed from Stopped to Stopped (Deallocated).

PowerShell command

Then you have to mark the VM as generalized. To make this operation, run the following command:

PowerShell command

Then you can save the VM image in the Storage Account by running the following command:

Regarding the parameters, the VM image will be stored in the following location:


Once the above command is executed, you can see your VM Image in the storage account.

VHDS folder

Deploy a VM from the image

To deploy the Azure VM from the image, you have also to use PowerShell:

Once the VM is deployed, I check again if the customization is set in the VM. As you can see in the below screenshot, the c:\temp folder is created and the .NET 3.5 feature is installed.

Remote Desktop Connection


In Microsoft Azure, it is possible to create VMs from the same image to deploy several VMs with the same baseline. However, in the new portal, you have to use PowerShell and not the GUI to generate the VM Image and to deploy VM from the image. But it is great for automation: you can create with a block of PowerShell a lot of Azure VM. If you like also deploy resources with JSON, you can specify the VM Image URL to deploy the Azure VM.

Related materials:

Views All Time
Views Today

Please rate this

Return to all posts

Microsoft's Server Management Tools Now Supports Windows Server 2012
vSphere Replication traffic isolation
The following two tabs change content below.
Romain Serre
Romain Serre
Senior consultant at Exakis
Romain Serre works in Lyon as a Senior Consultant. He is focused on Microsoft Technology, especially on Hyper-V, System Center, Storage, networking and Cloud OS technology as Microsoft Azure or Azure Stack. He is a MVP and he is certified Microsoft Certified Solution Expert (MCSE Server Infrastructure & Private Cloud), on Hyper-V and on Microsoft Azure (Implementing a Microsoft Azure Solution).