How to create VM from snapshot in Azure Portal

How To Create Azure Windows Virtual Machine From A Snapshot PowerShell

In this Azure tutorial, we will discuss How To Create Azure Windows Virtual Machine From A Snapshot using Azure Portal and PowerShell.

How to create VM from snapshot in Azure Portal

Let’s discuss How to Create A Virtual Machine From A Snapshot Azure Portal. Follow the below steps.

Step-1: Login to the Azure Portal (https://portal.azure.com/)

Step-2: Navigate to the respective virtual machine for the one you want to create the snapshot. Then click on the Disks link from the left navigation. Now click on the Disk name under the OS disk section as highlighted below.

How to create a VM from a snapshot in Azure

Step-3: Now, click on the + Create snapshot button on the Disk page as shown below.

Azure create vm from snapshot

Step-4: Fill out the below details as shown here

  • Resource group: You can select the existing resource group or if you don’t want to use the existing resource group, you click on the Create new link to create a new resource group.
  • Name: Provide a unique name for the snapshot.
  • Snapshot type: Select the snapshot type as per your requirement.
  • Storage typeSelect the storage type based on your requirements.

Once you have provided the above details, click on the Review + Create button.

create vm from snapshot

Now, it will validate all the details provided by you and will show you Validation Passed, once all the details are correct. then you can able to see the Create button is enabled. Click on the Create button to create the Snapshot for the Virtual machine.

You can able to see that the deployment was completed successfully without any issues. Click on the Go to Resource button to navigate to the Snapshot that you have created just now.

create vm from snapshot azure

Now our VM snapshot is ready to be used. Let’s see how to create a VM with this snapshot. Now as the next step, we need to create a managed disk for the new Virtual Machine.

Step-5: Search for the Disks on the Global search bar in the Azure Portal and click on the search result Disks as highlighted below.

Create Azure VM from Snapshot – PowerShell

Step-6: On the Disks Page, click on the +Add button to create a new managed Disk. Now on the Managed disk page, Provide the below details.

  • SubscriptionSelect the correct subscription that you want to use here to create the managed disk.
  • Resource group: Either you can choose your Existing resource group or you can also create a new one.
  • Disk Name: Provide a unique name for the disk.
  • Region: Make sure to select the region your snapshot was saved in, otherwise won’t be able to see your snapshot.
  • Size: Now click on the change size link to select the size based on your requirements and usage.
  • Source type: Choose the source type option as the snapshot.
  • Source Snapshot: Make sure to choose the snapshot that you have created above.

Finally, click on the Review + Create button as highlighted below.

how to create vm from snapshot in azure portal

Once, You click on the Review + Create button, it will validate all the details provided by you and will show you Validation Passed, once all the details are correct. then you can able to see the Create button is enabled. Click on the Create button to create the new managed disk.

Now you can able to see that the deployment is completed successfully without any issues. Click on the Go-To Resource button to navigate to the newly created managed Disk.

Create and restore Azure virtual machine snapshots

The next step is, on the Disk page, click on the + Create VM button to create the new Virtual Machine as highlighted below.

azure clone vm

Now, Fill in the below details on the Create a Virtual Machine page as highlighted below

  • Resource GroupProvide the Resource Group Details here. You can also create a new Resource group by clicking on the Create new link.
  • Virtual Machine Name: Provide a unique name for your Virtual Machine.
  • Image: Make sure to choose the proper image option.
  • Size: Select the size for your Virtual machine based on your requirements.
  • Public Inbound Ports: Select the Public Inbound Ports based on your requirements.
  • Select Inbound Ports: Provide the proper Select Inbound Ports as mentioned below.
  • License type: Select the Proper License type based on yours.
  • Would you like to use an existing Windows server License?: Select the correct choice based on your need.

Finally, click on the Review + Create button.

azure create vm from snapshot
azure snapshot vm

After validating all the details, you can able to see the Create button. Click on the Create button to create the Virtual Machine from the snapshot. After a few seconds, you can able to see the Deployment is completed successfully. Click on the Go to Resource button to see the newly created Virtual machine.

How To Create Azure Windows Virtual Machine From A Snapshot PowerShell

Well, here we will discuss a very usual topic, How To Create Azure Windows Virtual Machine From A Snapshot using PowerShell. Before starting the actual topic, we will discuss a bit on Azure Virtual Machine and the Prerequisites needed here.

Prerequisites

  • You must have a valid Azure account or Azure Subscription. If you have not created an Azure Account till now. Create a free Azure Account now.
  • Make sure to install the Azure PowerShell module on your machine. If you have not installed the Azure PowerShell module now, you can install the Azure PowerShell module now.

Create Azure Windows Virtual Machine Using PowerShell

Okay, let’s create a new Azure VM using PowerShell using the below steps.

Connect To Azure

Open the PowerShell ISE as Run as Administrator mode and then execute the below PowerShell cmdlet to connect to Azure using the Connect-AzAccount PowerShell cmdlet.

PS C:\WINDOWS\system32> Connect-AzAccount

Once, you will execute the above PowerShell cmdlet, it will prompt you to Provide your Azure Credentials. Make sure to log in with your Global Administrator credentials.

Creating a new resource group using PowerShell

In order to create an Azure Virtual machine, as a first step, we need to create a resource group using PowerShell. Use the below PowerShell script to create a resource group using PowerShell.

PS C:\WINDOWS\system32> New-AzResourceGroup -Name DemoVM -Location "East US"

Once, we have executed the above PowerShell cmdlet, you can able to see that the Resource group has been successfully created without any issues.

DemoVM is the name of our resource group and The region for the resource group is East US.

Step-by-Step Guide: Create Azure Windows Virtual Machine from a Snapshot (PowerShell Guide)

Creating a new virtual network using PowerShell

Now, our resource group is ready and as a next step, we need to create a new virtual network using PowerShell. Use the below PowerShell cmdlet to create a new virtual network using PowerShell.

$vmsnet = New-AzVirtualNetworkSubnetConfig -Name vmsubnet -AddressPrefix “10.0.2.0/24”

New-AzVirtualNetwork -Name TSINFOVN1 -ResourceGroupName DemoVM -Location “East US” -AddressPrefix “10.0.0.0/16” -Subnet $vmsnet

Once, we have executed the above PowerShell script, you can able to see, that the virtual network has been successfully created without any issue

How do I create a VM on Azure snapshot?
Name                   : TSINFOVN1
ResourceGroupName      : DemoVM
Location               : eastus
Id                     : /subscriptions/1cdf###-dee5-###-9c9c-feaa72a5cbd1/resourceG
                         roups/DemoVM/providers/Microsoft.Network/virtualNetworks/TSIN
                         FOVN1
Etag                   : W/"8b5818b8-231f-4102-a58c-d4059303c4d6"
ResourceGuid           : 16a24415-7405-4a35-9d00-0920e25bd07e
ProvisioningState      : Succeeded
Tags                   : 
AddressSpace           : {
                           "AddressPrefixes": [
                             "10.0.0.0/16"
                           ]
                         }
DhcpOptions            : {}
Subnets                : [
                           {
                             "Delegations": [],
                             "Name": "vmsubnet",
                             "Etag": "W/\"8b5818b8-231f-4102-a58c-d4059303c4d6\"",
                             "Id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd
                         1/resourceGroups/DemoVM/providers/Microsoft.Network/virtualNe
                         tworks/TSINFOVN1/subnets/vmsubnet",
                             "AddressPrefix": [
                               "10.0.2.0/24"
                             ],
                             "IpConfigurations": [],
                             "ServiceAssociationLinks": [],
                             "ResourceNavigationLinks": [],
                             "ServiceEndpoints": [],
                             "ServiceEndpointPolicies": [],
                             "PrivateEndpoints": [],
                             "ProvisioningState": "Succeeded",
                             "PrivateEndpointNetworkPolicies": "Enabled",
                             "PrivateLinkServiceNetworkPolicies": "Enabled",
                             "IpAllocations": []
                           }
                         ]
VirtualNetworkPeerings : []
EnableDdosProtection   : false
DdosProtectionPlan     : null

Till now, we have successfully created the resource group and the virtual network. Now, is the time to create a new Azure VM.

Creating Azure VM using PowerShell

Use the below PowerShell cmdlet to create an Azure Virtual machine.

$loginDetails = Get-Credential

New-AzVm -ResourceGroupName DemoVM -Name “TSINFOVM” -Location “East US” -VirtualNetworkName “TSINFOVN1” -SubnetName “vmsubnet” -addressprefix 10.0.2.0/24 -PublicIpAddressName “TSINFOIP1” -OpenPorts 3389 -Image win2019datacenter -Size Standard_D2s_v3 -Credential $loginDetails

Once we have executed the above PowerShell script, you can able to see the Azure Virtual machine has been created successfully without any issue

Can you create a VM from a snapshot?

The output looks like the below

ResourceGroupName        : DemoVM
Id                       : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourc
eGroups/DemoVM/providers/Microsoft.Compute/virtualMachines/TSINFOVM
VmId                     : b90fd30b-cefd-432c-a06f-81598e6dd91d
Name                     : TSINFOVM
Type                     : Microsoft.Compute/virtualMachines
Location                 : eastus
Tags                     : {}
HardwareProfile          : {VmSize}
NetworkProfile           : {NetworkInterfaces}
OSProfile                : {ComputerName, AdminUsername, WindowsConfiguration, 
Secrets, AllowExtensionOperations, RequireGuestProvisionSignal}
ProvisioningState        : Succeeded
StorageProfile           : {ImageReference, OsDisk, DataDisks}
FullyQualifiedDomainName : tsinfovm-a5a358.East US.cloudapp.azure.com

Just to make sure that the virtual machine has been created successfully, Let’s log in to the Azure Portal and check that the VM got created successfully. You can able to see below that the Azure VM was created successfully without any issues.

How do I clone an azure Windows virtual machine

Now let’s log in to the Azure virtual machine that we have created and will create two text files and will keep them on the Desktop.

The quickest way to create new VMs in Azure from existing VM snapshots

So now, Our Azure Virtual machine is ready with the test files. Now the next step is to create the snapshot of the Azure Virtual Machine.

Creating the Snapshot of the VM using PowerShell

You can use the below PowerShell script to create the snapshot of the Azure Virtual machine.

$myvm = Get-Azvm -ResourceGroupName DemoVM -Name TSINFOVM
$snapconfDetails = New-AzSnapshotConfig -SourceUri $myvm.StorageProfile.OsDisk.ManagedDisk.Id -Location “East US” -CreateOption copy
New-AzSnapshot -Snapshot $snapconfDetails -SnapshotName tsinfosnap -ResourceGroupName DemoVM

Once, we have executed the above script, you can able to see the snapshot of the Azure VM has been created successfully

Using PowerShell to Create Virtual Machine Snapshots

The output looks like the below

ResourceGroupName            : DemoVM
ManagedBy                    : 
Sku                          : Microsoft.Azure.Management.Compute.Models.SnapshotSku
TimeCreated                  : 12/10/2020 12:53:26 AM
OsType                       : Windows
HyperVGeneration             : 
CreationData                 : Microsoft.Azure.Management.Compute.Models.CreationData
DiskSizeGB                   : 127
DiskSizeBytes                : 136367308800
UniqueId                     : 25f77a5b-0bb9-4b04-955e-016da959d351
EncryptionSettingsCollection : 
ProvisioningState            : Succeeded
Incremental                  : False
Encryption                   : Microsoft.Azure.Management.Compute.Models.Encryption
Id                           : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/res
                               ourceGroups/DemoVM/providers/Microsoft.Compute/snapshot
                               s/tsinfosnap
Name                         : tsinfosnap
Type                         : Microsoft.Compute/snapshots
Location                     : eastus
Tags                         : {}
NetworkAccessPolicy          : AllowAll
DiskAccessId                 : 

Now the next step is to Create Azure windows virtual machine from the snapshot.

How to Create Azure Windows Virtual Machine From Snapshot

Well, we have created the Azure Windows Virtual Machine Snapshot above, Now We will be Creating Azure Windows Virtual Machine From Snapshot.

Getting the snapshot data

Let’s create a variable that will hold the snapshot data. Use the below PowerShell cmdlet to create the variable that will hold the snapshot data.

$snapshot = Get-AzSnapshot -ResourceGroupName DemoVM -SnapshotName tsinfosnap

Creating the managed disk using PowerShell

Now, we will have to create the managed disk using the above snapshot for the new VM.

$mydskconfig = New-AzDiskConfig -Location “East US” -SourceResourceId $snapshot.Id -CreateOption Copy

$newdisk = New-AzDisk -Disk $mydskconfig -ResourceGroupName DemoVM -DiskName tsinfoDisk

Initializing virtual machine configuration

As the next step, initialize the virtual machine configuration using the below PowerShell cmdlet.

$tsinfovmconfig = New-AzVMConfig -VMName TSINFOVMNEW -VMSize Standard_D2s_v3
$tsinfovmconfig = Set-AzVMOSDisk -VM $tsinfovmconfig -ManagedDiskId $newdisk.Id -CreateOption Attach -Windows

Creating the PublicIP for the VM using PowerShell

You can use the below PowerShell cmdlet for the PublicIP configuration.

$publicip = New-AzPublicIpAddress -Name TSINFONEWVMIP -ResourceGroupName DemoVM -Location “East US” -AllocationMethod Dynamic

Creating NIC for the new VM using PowerShell

Use the below PowerShell cmdlet to create the NIC for the virtual machine.

$myvnet = Get-AzVirtualNetwork -Name TSINFOVN1 -ResourceGroupName DemoVM

$mysubnet = Get-AzVirtualNetworkSubnetConfig -Name vmsubnet -VirtualNetwork $myvnet
$vmnic = New-AzNetworkInterface -Name “TSINFONEWVM_nic1” -ResourceGroupName DemoVM -Location “East US” -SubnetId $mysubnet.Id -PublicIpAddressId $publicip.Id

Creating the Azure Virtual Machine PowerShell

Now, as the next step, let’s add the newly created NIC to the VM configuration and create the Virtual machine using the below PowerShell cmdlet.

$tsinfovmconfig = Add-AzVMNetworkInterface -VM $tsinfovmconfig -Id $vmnic.Id
New-AzVM -VM $tsinfovmconfig -ResourceGroupName DemoVM -Location “East US”

Below is the complete PowerShell script that you can execute

$snapshot = Get-AzSnapshot -ResourceGroupName DemoVM -SnapshotName tsinfosnap
$mydskconfig = New-AzDiskConfig -Location “East US” -SourceResourceId $snapshot.Id -CreateOption Copy

$newdisk = New-AzDisk -Disk $mydskconfig -ResourceGroupName DemoVM -DiskName tsinfoDisk

$tsinfovmconfig = New-AzVMConfig -VMName TSINFOVMNEW -VMSize Standard_D2s_v3
$tsinfovmconfig = Set-AzVMOSDisk -VM $tsinfovmconfig -ManagedDiskId $newdisk.Id -CreateOption Attach -Windows
$publicip = New-AzPublicIpAddress -Name TSINFONEWVMIP -ResourceGroupName DemoVM -Location “East US” -AllocationMethod Dynamic

$myvnet = Get-AzVirtualNetwork -Name TSINFOVN1 -ResourceGroupName DemoVM

$mysubnet = Get-AzVirtualNetworkSubnetConfig -Name vmsubnet -VirtualNetwork $myvnet
$vmnic = New-AzNetworkInterface -Name “TSINFONEWVM_nic1” -ResourceGroupName DemoVM -Location “East US” -SubnetId $mysubnet.Id -PublicIpAddressId $publicip.Id

$tsinfovmconfig = Add-AzVMNetworkInterface -VM $tsinfovmconfig -Id $vmnic.Id
New-AzVM -VM $tsinfovmconfig -ResourceGroupName DemoVM -Location “East US”

Once, We ran the above script, you can able to see we got a Successful response as shown below

azure create vm from snapshot powershell

Now let’s connect to the newly created Azure VM and see if the folder and text file we have created is there or not. You can able to see the files and folder is there in the new VM as expected.

how to create disk from snapshot in azure

So, this is How To Create Azure Windows Virtual Machine From Snapshot.

FAQs

What is VM snapshots?

Virtual machine snapshots basically help to preserve the data and state of a virtual machine at some point in time. You can also consider that a VM snapshot is a copy of the disk file of your Virtual machine. VM snapshots are very helpful to immediately recover a virtual machine from a disaster.

Consider there is a scenario where you want to get certain data from the snapshot without restoring the complete VM. In that case, one of the excellent ways is to create a VM from the snapshot and get the specific data that you need.

Assuming, you have a little bit of an idea now about Azure Virtual Machine and VM snapshots, let’s discuss the Prerequisites needed to Create Azure Windows Virtual Machine From A Snapshot using PowerShell.

Wrapping Up

Well, In this article, we have discussed How To Create Azure Windows Virtual Machine From A Snapshot using PowerShell and Azure Portal?.