Share via

Powershell errors when Generalizing VM OS Disk to Managed image

Siegfried Heintze 1,906 Reputation points
Jan 20, 2023, 1:48 AM

I'm trying to following along with this tutorial:
[https://learn.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource#create-a-managed-image-of-a-vm-using-powershell]

I issue the following command with powershell 7.3.1:

Stop-AzVM -ResourceGroupName $rgName -Name $vmName -Force

I get this error:

Stop-AzVM: GenericArguments[0], 'Microsoft.Azure.Management.Compute.Models.VirtualMachine', on 'T MaxInteger[T]' violates the constraint of type 'T'.

Since I see there is a similar problem here: [[https://learn.microsoft.com/en-us/answers/questions/1120276/azure-powershell-error-genericarguments(0)-microso], I try the cloud shell.

On the last statement:

 New-AzImage -Image $image -ImageName 'articentgroupllc1635512619530-ubuntu-22-04-minimal' -ResourceGroupName $rgName

I get this error:

 New-AzImage: The Input HyperVGeneration property: 'V1' does not match with the HyperVGeneration property: 'Gen2' belonging to source: 'sourceVirtualMachine'.

ErrorCode: InvalidParameter

ErrorMessage: The Input HyperVGeneration property: 'V1' does not match with the HyperVGeneration property: 'Gen2' belonging to source: 'sourceVirtualMachine'.

ErrorTarget: hyperVGeneration

StatusCode: 400

ReasonPhrase: Bad Request
    OperationID : 3836df34-cf3e-4479-b02f-308ffb907219 

I tried using the portal and that may have worked. I will test it tomorrow. In any case I would like to automate this with local powershell command (instead of cloud shell) or (better yet) local azure cli.

I hope you can help me.

Thanks

Siegfried

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,224 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ramya Harinarthini_MSFT 5,341 Reputation points Microsoft Employee
    Jan 20, 2023, 3:39 PM

    @Siegfried Heintze Welcome to Microsoft Q&A, thank you for posting your here!!

    I have reproduced this issue in my test subscription if your Source Virtual Machine is Gen2 then you have to create the image config with -HyperVGeneration as V2 and was able to create the image successfully.

    please try with the below commands

    Make sure the VM has been deallocated.

    $vmName = "IMAGEGEN2VM" #VMname 
    $rgName = "Ramya" #Resourcegroup name 
    $location = "EastUS" #Region where the VM is deployed 
    $imageName = "myImage" #Image Name 
    Stop-AzVM -ResourceGroupName $rgName -Name $vmName -Force
    

    OperationId :

    Status : Succeeded

    StartTime : 1/20/2023 8:15:58 AM

    EndTime : 1/20/2023 8:16:11 AM

    Error :

    Set the status of the virtual machine to Generalized.

    Set-AzVm -ResourceGroupName $rgName -Name $vmName -Generalized
    

    OperationId :

    Status : Succeeded

    StartTime : 1/20/2023 8:16:15 AM

    EndTime : 1/20/2023 8:16:16 AM

    Error :

    Create the image configuration and Create the Image

    $vm = Get-AzVM -Name $vmName -ResourceGroupName $rgName 
    $image = New-AzImageConfig -Location $location -SourceVirtualMachineId $vm.Id -HyperVGeneration "V2" 
    New-AzImage -Image $image -ImageName $imageName -ResourceGroupName $rgName
    

    ResourceGroupName : Ramya

    SourceVirtualMachine : Microsoft.Azure.Management.Compute.Models.SubResource

    StorageProfile : Microsoft.Azure.Management.Compute.Models.ImageStorageProfile

    ProvisioningState : Succeeded

    HyperVGeneration : V2

    Id : /subscriptions/SubID/resourceGroups/Ramya/providers/Microsoft.Compute/images/myImage

    Name : myImage

    Type : Microsoft.Compute/images

    Location : eastus

    ExtendedLocation :

    Tags : {}

    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    3 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.