{"id":268,"date":"2019-08-18T18:56:44","date_gmt":"2019-08-18T08:56:44","guid":{"rendered":"http:\/\/kswp01.azurewebsites.net\/?p=268"},"modified":"2019-08-18T19:04:27","modified_gmt":"2019-08-18T09:04:27","slug":"restoring-azure-vm-from-snapshot","status":"publish","type":"post","link":"https:\/\/kswp01.azurewebsites.net\/?p=268","title":{"rendered":"Restore Azure VM from Snapshot"},"content":{"rendered":"\n<h3>How to restore an Azure VM from a snapshot<\/h3>\n\n\n\n<!--more-->\n\n\n\n<div style=\"height:43px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">#Provide the name of your resource group \n$resourceGroupName ='yourResourceGroupName' \n\n#Provide the name of the snapshot that will be used to create OS disk \n$snapshotName = 'yourSnapshotName' \n\n#Provide the name of the OS disk that will be created using the snapshot \n$osDiskName = 'yourOSDiskName'\n\n$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName \n\n$diskConfig = New-AzDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy \n\n$disk = New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName \n\n# Get the VM  \n$vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name myVM  \n\n# Make sure the VM is stopped\\deallocated \nStop-AzVM -ResourceGroupName $resourceGroupName -Name $vm.Name -Force \n\n# Set the VM configuration to point to the new disk   \nSet-AzVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name  \n\n# Update the VM with the new OS disk \nUpdate-AzVM -ResourceGroupName $resourceGroupName -VM $vm  \n\n# Start the VM \nStart-AzVM -Name $vm.Name -ResourceGroupName $resourceGroupName<\/pre>\n\n\n\n<h3>References<\/h3>\n\n\n\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/scripts\/virtual-machines-windows-powershell-sample-create-vm-from-snapshot\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/scripts\/virtual-machines-windows-powershell-sample-create-vm-from-snapshot<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/windows\/os-disk-swap\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/windows\/os-disk-swap<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to restore an Azure VM from a snapshot<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/268"}],"collection":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":7,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions\/288"}],"wp:attachment":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}