Safely Remove or Eject a Disk Using the Command Line

Use the diskpart utility to safely remove a disk drive. This is useful when you have no GUI, for example in Server Core or Hyper-V Server.

  1. On command prompt, type "diskpart" and wait for the new prompt, then type "list volume". Take note of the number of your desired volume by watching its drive letter (be carefull!!!)
  2. Type "select volume <number>", where <number> is the number of your USB storage.
  3. Then, type "remove all dismount". Type "exit" to leave diskpart. Enjoy! ;)
  4. Now you can safely remove your USB storage device from the Hyper-V server.

According to the diskpart removeĀ“s help (type "help remove" inside diskpart):


" DISMOUNT    This parameter may be used if 1) all drive letters and
mounted folder paths have been removed from the volume, or
2) the ALL parameter is specified.  This parameter
specifies that the file system is to be dismounted and
the volume taken offline. If other processes are using
the volume, DiskPart closes any open handles before
dismounting the file system and taking the volume offline.
You can bring the volume online by assigning it a driver
letter, by creating a mounted folder path to the volume, or
by using the ONLINE command. DISMOUNT will fail if used
on a volume that has any remaining drive letters or mounted
folder paths. For scripting, using REMOVE ALL DISMOUNT is