You have a v2 Azure Virtual Machine that has been generalized and are ready to capture it using Azure PowerShell v0.9.x? All right, buckle your seat belt and follow this guide, at the end you should have your captured VHD in your storage account.

This post assume you already have a virtual machine on Azure that have been generalized and you want to capture it. You can find out how to generalize your VM and other alternatives for your capture in this article: Step by Step: How to capture your own custom virtual machine image under Azure Resource Manager

Capture VM image with PowerShell v0.9.x

Here is the 3 calls that you need to perform in PowerShell to capture your image...

# Deallocate the virtual machine
Stop-AzureVM -ResourceGroupName 'CaptureVmImageRG' -Name 'CaptureVmImage'

You should have a Succeeded status.
After Stop-AzureVM Call

# Set the Generalized state to the virtual machine
Set-AzureVM -ResourceGroupName 'CaptureVmImageRG' -Name 'CaptureVmImage' -Generalized

You should have an OK StatusCode.
After Set-AzureVM Generalize Call

# Capture the image to storage account.
Save-AzureVMImage -ResourceGroupName 'CaptureVmImageRG' -VMName 'CaptureVmImage' -DestinationContainerName 'mytemplates' -VHDNamePrefix 'template' -Path C:\temp\capturevmtest\SampleTemplate.json

The -Path parameter of the Save-AzureVMImage cmdlet will download a copy of the the ARM template file generated in the storage account and save it where you specified. The JSON will also be outputted in the PowerShell window.

After Save-AzureVMImage Call

Jump to Capture is done, what's next?