Set delete options when creating a VM Not available

David Pereira 65 Reputation points
2025-06-05T13:21:59.7433333+00:00

I have a W11 AVD host and I use Nerdio to manage the environment.

I have created a PowerShell script to attach an existing azure managed disk to the AVD Host VM and that works fine, I need to ensure the disk is not deleted if the VM is deleted so I've created a lock "delete" on the managed disk and that's fine as well.

My problem is when using Nerdio to re-image this VM it tries to delete the data disk as this is the default behaviour when you delete a VM in azure so Nerdio support recommended changing the Delete options of the data disk as per MS documentation to detach instead of delete, but this options is not available on the portal and the command doesn't fail but also doesn't prevent the deletion.

The disk is protected by the lock but the Nerdio orchestration fails as it tries to delete the disk.

Nerdio errorUser's image

Example of the setting I'm trying to apply via PS script

# Ensure the disk is detached (not deleted) when VM is deleted

$vm.StorageProfile.DataDisks | ForEach-Object { $_.DeleteOption = 'Detach' }

# Apply changes

Update-AzVM -ResourceGroupName $resourceGroup -VM $vm

My AZ Portal notice there's no option to delete with VM like in the documentation.oak1MS Documentationoak2

regards,

David

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

1 answer

Sort by: Most helpful
  1. Nikhil Duserla 7,935 Reputation points Microsoft External Staff Moderator
    2025-06-05T15:22:09.6466667+00:00

    Hello @David Pereira,

    In Azure, depending on how you delete a virtual machine (VM), only the VM resource itself may be deleted, while associated resources such as the OS disk, data disks, network interfaces, and public IP addresses will not be removed automatically. This behavior depends on how the VM was created and the deletion options chosen. Additionally, you can take a snapshot of the VM’s managed disk and use it to create a new disk or attach it to another VM as needed.

    User's image

    When you no longer need a data disk that's attached to a virtual machine, you can easily detach it. This removes the disk from the virtual machine, but doesn't remove it from storage- https://learn.microsoft.com/en-us/azure/virtual-machines/windows/detach-disk

    If you have any further queries, do let us know.


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.