Create an image of a VM using Powershell in Azure
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.