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)
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
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
does this script helps to detach the same luns after unmounting?
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
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...!
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