Rescanning your storage in an ESX cluster
Nothing is more annoying then having to rescan your VMFS filesystems or HBA’s in ESX3. Going from node to node and click all the time. If you have one or two nodes this is do-able, but i’m maintaining multiple clusters with a grand total of 30 nodes..
However VMWare created PowerCLI, perhaps the most powerfull piece of management software VMWare has released to date. With PowerCLI you can automate the most annoying of jobs with ease.
Here is a little script to let all your nodes scan their HBA’s and VMFS filesystems.
You can add an host as argument to the script (FQDN), to let it run the commands at the host only.
connect-viserver your.virtualcenter.box
if ($args -eq $null)
{
get-vmhost | foreach-object
{
get-vmhoststorage -VMHost $_.name -RescanAllHba -RescanVmfs
}
}
else
{
get-vmhoststorage -VMHost $args -RescanAllHba -RescanVmfs
}
*UPDATE* changed the script, see comments for more info.
I think you can just Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs -Refresh and it will be faster.
I’ve never tried it with the -Refresh at same time as the rescans, I know the rescans will work by themselves, so it’s worth a try.
even better, it seems the -Refresh isn’t needed at all. This will auto-run if the esx node sees a new vmfs datastore or a new storage device is initialized.
The biggest usage of these scripts is for not-powershell users that have to do something fast. Just add the functionality in scripts and let them use these.
I’ve rewritten the script so that it now has an argument option. I’ll post that instead of the current.