Azure - Create VM Image and Restore VM from Image


Here is an easy way how you can simply Snapshot, “freeze” your Azure Virtual Machine and then restore it whenever you want. This can be useful for creating Virtual Machines for testing purpose.

With described process, you can still use your Virtual Machine after creating Snapshot.

Create Image from Azure Virtual Machine

Prepare you Virtual Machine

This is really important process where you prepare you Virtual machine:

  1. In the Azure portal, Connect to the virtual machine. For instructions, see How to sign in to a virtual machine running Windows Server.
  2. Open a Command Prompt window as an administrator.
  3. Change the directory to %windir%\system32\sysprep, and then run sysprep.exe.
  4. The System Preparation Tool dialog box appears. Do the following:
  • In System Cleanup Action, select Enter System Out-of-Box Experience (OOBE) and make sure that Generalize is checked. For more information about using Sysprep, see How to Use Sysprep: An Introduction.
  • In Shutdown Options, select Shutdown.
  • Click OK.

Sysprep shuts down the virtual machine, which changes the status of the virtual machine in the Azure portal to Stopped.

Create Snapshot

  1. In the Azure portal, navigate to your Virtual Machine.

  2. Select Disks on Virtual Machine menu, after selecting your Virtual Machine.

  3. Select you OS disk on the right 'You could go directly to you disk from Azure portal

  4. Select Create snapshot command from action menu on the top right

  5. Name your snapshot and select Create

Now you have Snapshot of your Virtual machine (Disk).

Create Image

Best way to create Image from snapshot is with powershell:

  1. Create variables $rgName = "myResourceGroup" $location = "EastUS" $snapshotName = "mySnapshot" $imageName = "myImage"
  2. Connect to Azure Login-AzureRmAccount
  3. Get the snapshot $snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
  4. Create the Image configuration $imageConfig = New-AzureRmImageConfig -Location $location $imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
  5. Create the Image New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig

Image with $imageName is created and store on Azure portal.

Create/Restore Virtual Machine from Image

If you want to restore Azure Virtual Machine or create new one from Image. On “All resources” select your Image. On up right Menu select Create VM and follow instruction like creating new Virtual Machine.

That’s all, now you have your “new” Virtual Machine created.


Azure Virtual Machine is not running / starting

If you have followed this article: be aware that after this process Virtual machine is not usable and you’ll get errors and Virtual Machine will not run or start.

If any of Errors below you are having there is no fixing that. Your virtual machine is not usable any more.

Set-AzureRmVMAccessExtension : Long running operation failed with status 'Failed'.
ErrorCode: VMAgentStatusCommunicationError
ErrorMessage: VM '' has not reported status for VM agent or extensions. Please verify the VM has a running VM agent, and can establish outbound connections to Azure storage.
StartTime: 8/1/2017 12:41:40 PM
EndTime: 8/1/2017 1:07:06 PM
OperationID: 54486c40-20b6-4a97-be62-b4fcf23a68d0
Status: Failed
At line:1 char:1
+ Set-AzureRmVMAccessExtension -ResourceGroupName "" -VMName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmVMAccessExtension], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.SetAzureVMAccessExtensionCommand

Subscribe to our Newsletter


An error prevents us from coming into contact

We are sorry to give you this error message. Something went into our way, please try send again.

Talk to you soon,
Unitfly Team

Thank you for getting in touch!

We have received your message and would like to thank you for writing to us. If your inquiry is urgent, please use the telephone number listed below, to talk to one of our staff members. Otherwise, we will reply by email shortly.

Talk to you soon,
Unitfly Team

Cookies Private Policy.

Like many sites, we use "cookies" to collect information. You can instruct your browser to refuse all cookies or to indicate when a cookie is being sent. However, if you do not accept cookies, you may not be able to use some portions of our Site.

Read more about cookies here.

Thank you very much for subscribing!

Only one step is left to complete your subscription.

We want to be certain we have your permission so we'll send you an e-mail with confirmation link. Please check your inbox!

Talk to you soon,
Unitfly Team

An error prevents us from coming into contact

We are sorry to give you this error message. Something went into our way, please try send again.

Talk to you soon,
Unitfly Team