Rescan VMware cluster HBA’s via Powershell

Ever wanted to trigger a recsan of storage for all hosts in a given cluster? There may be a reason why you would want to do this via a script rather than a gui and if so, this is it.

I have written it as a function.

The code will connect to a VC, identify the cluster (you give it the cluster name as a parameter), get a list of hosts, and then for each host, trigger a rescan.

Unfortunately, it runs serially, rather than triggering a parallel run. At this stage it doesn’t really matter to me, but at some point, I will write a version that does the rescan’s in parallel.

Function Rescan-ClusterHBA
param ([string]$vmClustername, $viserver)
Connect-VIServer $viserver

$vmClusterPointer = get-cluster $vmClusterName
$vmcluster = $vmClusterPointer | Get-View

$vmhosts = $vmcluster | select -Expand host

foreach ($vmhost in $vmhosts)
	Get-VMHost -Id $vmhost
	Get-VMHostStorage -vmhost (Get-VMHost -Id $vmhost) -RescanAllHba

Leave a comment

Filed under Equallogic, Powershell, VMware

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s