How to create a snapshot of Azure VM using PowerShell

Recently, I got a requirement to create a snapshot of Azure VM using PowerShell. I did it successfully with the steps below.

How to create a snapshot of Azure Virtual Machine 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 see below the snapshot of the Azure VM has been created successfully.

how to create a snapshot of azure vm

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                 : 

You can also check out how to snapshot Azure VM using Azure Portal.

You may also like following the articles below

Conclusion

This article discussed the quick steps to create a snapshot of Azure VM using PowerShell. Thanks a lot for reading this article !!!