How can i detach a disk from azure VM using REST-API ?

DEEPAK GULATI 1 Reputation point
2022-05-24T15:34:24.183+00:00

I want to detach a disk from a Particular VM which i recovered from another VM but i don't see any "rest-api" command to achieve that and if i try to directly delete the disk, it says "Operation-not-allowed" as it's being used by particular VM. Please suggest

205168-image.png

Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sumarigo-MSFT 47,506 Reputation points Microsoft Employee Moderator
    2022-05-25T08:16:58.84+00:00

    @DEEPAK GULATI Welcome to Microsoft Q&A Forum, Thank you for posting query here!

    Firstly you need to to detach the Disk through portal,Powershell or SDK -> then you can delete disk using REST API . Presently there is No API for detaching the disk

      PS for Detaching the disk   
      
     $VirtualMachine = Get-AzVM `  
           -ResourceGroupName "<RG>" `  
           -Name "teststoragedisk"  
             
        Remove-AzVMDataDisk `  
           -VM $VirtualMachine `  
           -Name "removeusingPS"  
              
        Update-AzVM `  
           -ResourceGroupName "<RG>" `  
           -VM $VirtualMachine  
    

    DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}?api-version=2021-12-01

    205393-image.png

    205348-image.png

    If you wish you may leave your feedback here, All the feedback you share in these forums. will be monitored and reviewed by the Microsoft engineering teams responsible for building Azure.

    Please let us know if you have any further queries. I’m happy to assist you further.

    ----------

    Please do not forget to 205354-screenshot-2021-12-10-121802.png and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

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