When trying to unmount a datastore from one of my 4 ESXi hosts, I receive a message that it's in use.

The full error stack I see is:

Call "HostDatastoreSystem.RemoveDatastore" for object "datastoreSystem-57" on vCenter Server "TSD-VCENTER2.jhuapl.edu" failed.

I've tried the following:

  • Removing the datastore from the other three ESXi 5.1 hosts (successful)
  • Running the following PowerCLI script to list all ISOs (there were some):
Get-VM | Get-CDDrive | FT Parent, IsoPath, HostDevice
  • Luckily I didn't need any of them so I did an unmount across the board:
Get-VM | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False
  • Ran the first script to list all ISOs again (no host devices or IsoPaths mounted now)
  • Looked for any hard disks that could possibly be pointing to the vmdatastore:
 Get-VM | Get-HardDisk | Where-Object {$_.Filename -like "*vmdatastore*"}

I was unaware that PowerCLI doesn't include templates in the "Get-VM" command (though in retrospect it makes perfect sense -- d'oh)

On a hunch, I ran the following to see if any templates had CD Drives attached:

Get-Template | Get-CDDrive | FT *

Lo and behold, it found some! So, I ran the following to convert the VMs to templates:

Get-Folder -Name "04. Templates" | Get-Template | Set-Template -ToVM -Confirm:$False

I then ran the following to Set the template drives to empty:

Get-Folder -Name "04. Templates" | Get-VM | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False

And double-checked that it worked:

Get-Folder -Name "04. Templates" | Get-VM | Get-CDDrive | FT *

However, still no luck. I receive the same error, that the datastore is in use.

I'm currently migrating some VMs to another of the ESXi hosts to see if a simple shutdown/restart will do the trick.

Anyone have any other ideas as to why this could be happening?


Found the answer -- the issue, apparently, was with snapshots as far as I can tell.

There must have been snapshots that included references to the datastore in question.

Fortunately I was in a position where I could delete all the snapshots.

After deleting all snapshots, the datastore allowed itself to be deleted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.