How to detach a data disk from a Windows virtual machine
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.
If you detach a disk it is not automatically deleted. If you have subscribed to Premium storage, you will continue to incur storage charges for the disk. For more information refer to Pricing and Billing when using Premium Storage.
If you want to use the existing data on the disk again, you can reattach it to the same virtual machine, or another one.
Detach a data disk using the portal
- In the left menu, select Virtual Machines.
- Select the virtual machine that has the data disk you want to detach and click Stop to deallocate the VM.
- In the virtual machine pane, select Disks.
- At the top of the Disks pane, select Edit.
- In the Disks pane, to the far right of the data disk that you would like to detach, click the detach button.
- After the disk has been removed, click Save on the top of the pane.
- In the virtual machine pane, click Overview and then click the Start button at the top of the pane to restart the VM.
The disk remains in storage but is no longer attached to a virtual machine.
Detach a data disk using PowerShell
In this example, the first command gets the virtual machine named MyVM07 in the RG11 resource group using the Get-AzureRmVM cmdlet and stores it in the $VirtualMachine variable.
The second line removes the data disk named DataDisk3 from the virtual machine using the Remove-AzureRmVMDataDisk cmdlet.
The third line updates the state of the virtual machine, using the Update-AzureRmVM cmdlet, to complete the process of removing the data disk.
$VirtualMachine = Get-AzureRmVM -ResourceGroupName "RG11" -Name "MyVM07" Remove-AzureRmVMDataDisk -VM $VirtualMachine -Name "DataDisk3" Update-AzureRmVM -ResourceGroupName "RG11" -VM $VirtualMachine
For more information, see Remove-AzureRmVMDataDisk.
If you want to reuse the data disk, you can just attach it to another VM