skip to Main Content

I’m trying to update a windows vm to have a system assigned managed identity.

I tried using the following commands.

$Vm = Get-AzVM -Name $vm_name -ResourceGroupName $rg -Status
Update-AzVM -ResourceGroupName $rg -VM $vm -IdentityType SystemAssigned

I’m getting the error message

Cannot convert the "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineInstanceView" value of type "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineInstanceView" to type "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine".

2

Answers


  1. Chosen as BEST ANSWER

    It turns out that the -Status flag on Get-AzVM returns a different object than without the -Status flag.

    Try removing it and you will get an object that is compatible with Update-VM

    $Vm = Get-AzVM -Name $vm_name -ResourceGroupName $rg
    

  2. i think the script is lil wrong with the variables, let me give you an updates script, hopefully it will works.

    # Get the VM
    $Vm = Get-AzVM -Name $vm_name -ResourceGroupName $rg -Status
    
    # Update the VM with SystemAssigned Managed Identity
    Update-AzVM -ResourceGroupName $rg -VM $Vm -IdentityType SystemAssigned
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search