Capture an Azure RM VM

Capture an ARM VM as a new template including JSON file.

John Savill

December 19, 2015

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Q. How do I capture an Azure RM VM?

A. The new Azure portal has a capture action for new RM VMs but not for RM VMs. Therefore to capture a VM use the REST APIs or PowerShell. Below is the PowerShell to capture a VM after it has been SYSPREP'd (sysprep /oobe /generalize /shutdown) and shutdown. I am also using the new Azure PowerShell 1 AzureRM cmdlets.

Login-AzureRmAccount #ARM logonStop-AzureRmVM -ResourceGroupName "RG-SCUSA" -Name "DemoVM" -ForceSet-AzureRmVM -ResourceGroupName "RG-SCUSA" -Name "DemoVM" -Generalized Save-AzureRmVMImage -ResourceGroupName "RG-SCUSA" -Name "DemoVM" `    -DestinationContainerName "custtemp" `    -VHDNamePrefix "template" -Path "d:tempCaptTemplate.json" 

The final command will not only save the JSON template to the path specified but also will show it on screen. Also in the storage account will be a folder structure called systemMicrosoft.ComputerImages which will contain the VHD and JSON file.

Note that the custom image can now be created from the VHD by specifying the VHD as the image and the createOption as FromImage. You can use the JSON template supplied as a foundation but will need to add detail around network adapters. You can also create using PowerShell but once again make sure you use the fromImage option as the CreateOption with the Set-AzureRmVMOSDisk cmdlet and pass the image URI using -SourceImageUri.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like