My notes and ramblings, normally about automation

PowerCLI - Rescan HBAs for a Cluster on a Host by Host Basis

· Read in about 1 min · (154 Words)
Cluster ESXi Host PowerCLI PowerShell VMware vSphere

After having some bad luck with rescanning HBAs for entire clusters or datacenters all at the same time (Cliff’s Notes: the LUNs ended up looking like array based snapshots and therefore unusable), it was decided that any rescans should be done on an individual host basis. Below is the script I created to achieve this goal.

When you run the script, it will ask for the Cluster name so you don’t have to modify the code.

#Rescan HBAs for a cluster on a host by host basis 
$InputCluster = Read-Host "Cluster Name" $vmhosts = get-cluster 
$InputCluster | get-vmhost 

foreach ($i in $vmhosts) { 
    Write-Host "Starting rescan of all HBAs on $i" 
    $i | Get-VMHostStorage -RescanAllHba | Out-Null 
    Write-Host "Rescan of all HBAs on $i is complete" 
    Write-Host ""

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.