Below are best practices to unmount datastore from vCenter.
Below checks should be considered.
-No VM resides on the datastore
-The datastore is not part of Datastore cluster
-The datastore is not managed by storage DRS
-SIOC is disabled for this datastore
-The datastore is not used for vSphere HA heartbeat.
It seems, Unmount API itself does not do these checks, We need to explicitly handle these checks in script.
From ESXi host
- Only check feasible is : -No VM resides on the datastore
-Remaining checks are not easy to code if we want to unmount from ESXI directly. The reason is ESXi can not know weather SIOC/SDRS etc are enabled.
-If you have to unmount from ESXi, you first should check either manaully or pro-grammatically from VC & if everything is OK, finally unmount/detach the datastore from ESXi
I went through this script, this script will work fine BUT there is NO any aforementioned checks. Hence please be cautious while using this script. If you do not consider these check & run this script on datacenter where multiple hosts/datastores/datastore clusters are there, it may lead to some implications.
To answer your question: Same script work even to unmount datastore from ESXi.
Steps: Save this script as .ps1 (powershell) >>add the datastore name to be unmounted in script>>run this script from powershell (make sure POwerCLI is also installed in the same system)>>it will ask you for credential>>add your ESXi credentials>> it should work to unmount from your host.
I re-iterate, plz make sure you consider all checks I mentioned above.