Highlighted
Contributor
Contributor

Unmount and detach the datastores from couple of ESXi hosts

Jump to solution

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
Highlighted
User Moderator
User Moderator
5 Replies
Highlighted
User Moderator
User Moderator

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

Highlighted
Contributor
Contributor

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

0 Kudos
Highlighted
User Moderator
User Moderator

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
Highlighted
Contributor
Contributor

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
Highlighted
User Moderator
User Moderator