I was recently working with a user and we had to end up performing rescan for datastores for all ESXi hosts that were connected to the Cluster on the vCenter Server.
I thought of performing this using PowerCli, hence the title Rescan Datastores using PowerCli.
Let me first give you a background of what was going on with this issue.
There was an LUN that was extended on the storage side and a rescan was performed for one of the hosts by connecting to the vCenter Server.
The extended size was detected and the datastore size was increased to the new value of the LUN.
The interesting thing was that the datastore size used to keep changing back to the previous value once very half an hour.
A simple rescan of the datastore used to keep fixing the issue.
I checked the logs on the vCenter and one of the ESXi hosts on which we were performing the rescan, but there was unusual logging, everything seemed to be fine.
Now, this one was peculiar. Later, I realized that this could be an issue with one of the ESXi hosts connected to the vCenter Server within the cluster might be reporting the old value of the datastore, which is why vCenter used to show the old value for all the hosts.
Now, I could have done this by just selecting the cluster and right click > Rescan for datastores
But rescanning the cluster can take a long time and can disrupt some operations on the cluster level as seen by this warning message.
Hence, I decided to Rescan Datatsores using PowerCli.
I knew that the command Get-VMHostStorage will perform the rescan of the host when the correct parameters are provided.
The three important parameters that one needs to be aware of are:
- Refresh
- RescanAllHba
- RescanVmfs
If I had to perform this perform this one a single host, the command will look something like below:
Get-VMHostStorage -VMHost 192.168.1.11 -RescanAllHba -RescanVmfs
Now that we know the usage of the command, let us write a one-liner that will perform the rescan datastores using PowerCli for all hosts within the cluster one after the other.
Get-Cluster ‘Name_of_your_cluster‘ | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs
The other advantage is that you are saving time by not logging into each host and performing this manually.
I hope this has been informative and thank you for reading!
2 Comments
Hi.
How did you check and confirm whether re scanning through CLI wont disrupt the vmotion and other task at cluster level? Is there any explanation?
Rescan will not affect storage vMotion. Rescan queries the storage array and finds out if there are any devices presented or not and shows them on the UI, and if there are any missing mounts, it mounts those devices as datastores.