question

DEEPAKGULATI-8313 avatar image
0 Votes"
DEEPAKGULATI-8313 asked SumanthMarigowda-MSFT answered

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

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
image.png (28.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SumanthMarigowda-MSFT avatar image
0 Votes"
SumanthMarigowda-MSFT answered

@DEEPAKGULATI-8313 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.



image.png (64.9 KiB)
image.png (28.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.