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 logon
Stop-AzureRmVM -ResourceGroupName "RG-SCUSA" -Name "DemoVM" -Force
Set-AzureRmVM -ResourceGroupName "RG-SCUSA" -Name "DemoVM" -Generalized
Save-AzureRmVMImage -ResourceGroupName "RG-SCUSA" -Name "DemoVM" `
    -DestinationContainerName "custtemp" `
    -VHDNamePrefix "template" -Path "d:\temp\CaptTemplate.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 system\Microsoft.Computer\Images\<your container name> 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.