Rescan Datastores using PowerCli – Get-VMHostStorage

0

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.

Rescan Datastores using PowerCli - Get-VMHostStorage

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!

Share.

About Author

I am Adil Arif, working as a Senior Technical Support Engineer at Rubrik as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.

Leave A Reply

LIKE WHAT YOU'VE READ?
If so, please join the community.  I’d love to send you exclusive content right to your email, and I’ll send you a free copy of my book, VMware vSphere 6.0 Lab on Workstation too!
Enter your name and email below, and I’ll see you on the inside!

SUBSCRIBE