When you re-image or delete a host it deletes any managed disks attached to the VM, it would be nice to have the option to change that behaviour to detach instead of delete or to be able run a script before the re-image process to detach any disks without having to do it manually via the azure portal.
I'm attaching the disk via Nerdio scripted actions and I have tried to circumvent this limitation by changing the default behaviour for data disks by using the following command but Nerdio just ignores the setting and tries to delete the disk.
# Ensure the disk is detached (not deleted) when VM is deleted
$vm.StorageProfile.DataDisks | ForEach-Object { $_.DeleteOption = 'Detach' }
A lock on the disk prevents the disk from getting deleted but means the re-image process fails.

Comments (2 comments)