VMware Cloud Community
routing7
Contributor
Contributor
Jump to solution

Unmount and detach the datastores from couple of ESXi hosts

I'm trying to unmount and then detach couple of datastores from few ESX hosts. However, it is very taking long time to do so.

do you have any script already available to do the same work. (Note: about 50 datastores are connected to the hosts, but, I want to unmount and detach only 20 datastores)

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

5 Replies
LucD
Leadership
Leadership
Jump to solution

Did you already try something like this?

Get-Datastore -Name (Get-Content datastores.txt) -PipelineVariable ds | 
ForEach-Object -Process {
    Get-VMHost -Datastore $ds -PipelineVariable esx |
    ForEach-Object -Process {
        $storSys = Get-View -Id $esx.ConfigManager.StorageSystem
        $storSys.UnmountVmfsVolume($ds.ExtensionData.Info.vmfs.uuid)
    }
}


As an alternative you could also use the esxcli command (see KB2004605) via the Get-EsxCli cmdlet. 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

routing7
Contributor
Contributor
Jump to solution

does this script helps to detach the same luns after unmounting?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, because a Detach is done on a LUN, not on a Datastore.
That would require additional logic


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
routing7
Contributor
Contributor
Jump to solution

ok, my plan is, first unmount the datastore and then after detach the LUN from a host.

Would it be possible to go with a single script to do both tasks or need to write two different scripts? like one script for unmount the datastore and the other one for detach the LUN...!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use the functions from Alan's document, see Datastore Mount/Unmount Detach/Attach functions - VMware Technology Network VMTN


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference