I know that there are two types of virtual machine images, Generalized and Specialized.
If the OS has been generalized/de-provisioned, the virtual machine must be shut down in order to capture it as a VM Image. Once the VM has been captured as a VM Image, the virtual machine will automatically be deleted.
If the OS is specialized, the virtual machine can be captured while it is running or shut down. The captured virtual machine remains untouched. If an application consistent or cross-disk capture is needed, we recommend the virtual machine is shut down prior to capturing the VM Image.
Here I am trying to capture the image without shutting down the VM (Specialised). I have the below code to capture the image using PowerShell.
Save-AzureRmVMImage -ResourceGroupName $rgame -VMName $vmname -DestinationContainerName $container -VHDNamePrefix $vhdname
but the above code throws the error as below
Save-AzureRmVMImage : Capture operation cannot be completed because the VM is not generalized.
ErrorCode: OperationNotAllowed
ErrorMessage: Capture operation cannot be completed because the VM is not generalized.
StatusCode: 409
I found I can set VM to Generalized using Set-AzureRmVM
Set-AzureRmVM -ResourceGroupName 'CaptureVmImageRG' -Name 'CaptureVmImage' -Generalized
Is there anyway so that I can set VM to Specialized and capture the image. Can someone please provide a working Powershell command to create a Specialized capture of a running VM for backup 'point in time' purposes, or any other mechanism e.g. resource explorer.
Thanks in advance.