Creating an image directly from the VM ensures that the image includes all of the disks associated with the VM, including the OS disk and any data disks. This example shows how to create a managed image from a VM that uses managed disks.
Before you begin, make sure that you have the latest version of the AzureRM.Compute PowerShell module, which must be version 5.7.0 or later. To find the version, run
Get-Module -ListAvailable AzureRM.Compute in PowerShell. If you need to upgrade, see Install Azure PowerShell on Windows with PowerShellGet. If you are running PowerShell locally, run
Connect-AzureRmAccount to create a connection with Azure.
To create a VM image, follow these steps
Create some variables.
Make sure the VM has been deallocated.
Set the status of the virtual machine to Generalized.
Get the virtual machine.
Create the image configuration.
Create the image.