Scan ESX HBA’s – PowerShell’s your friend

Many of you out there, working in the IT like me, are using scripts to automate a variety of tasks. There are many script languages available and PowerShell from Microsoft is one of them. A very powerful scripting language and also, as many of you probably know, useable in VMware environments.

The past few months I created some scripts to make my life easier. Perhaps it is of use to you as well.

Here is a little script to scan the HBA’s on every ESX server in a particular ESX cluster. Very handy when adding datastores to a cluster with many ESX nodes. Saves us some RSI advancing GUI clicking. :-)

#Check input
If ($args[0] -eq $null){
Write-Host
Write-Host “Error, missing parameters. Command syntax is:”
Write-Host
Write-Host ” .\ScanClHba.ps1 <virtualcenter hostname> <clustername>”
Write-Host
Exit
}

If ($args[1] -eq $null){
Write-Host
Write-Host “Error, missing parameters. Command syntax is:”
Write-Host
Write-Host ” .\ScanClHba.ps1 <virtualcenter hostname> <clustername>”
Write-Host
Exit
}

#Connect to VirtualCenter
$VIserver = Connect-VIServer -Server $args[0] -Protocol https

#Scan HBA’s
get-cluster -name $args[1] | get-vmhost | Get-VMHostStorage -RescanAllHBA
get-cluster -name $args[1] | get-vmhost | Get-VMHostStorage -RescanAllHBA

#Disconnect van VC
Disconnect-VIServer -Server $VIserver -Confirm:$False

In the VMware environment I am currently working on it necessary to scan twice before a new LUN is seen. That’s the reason I execute the scan command twice in the script.

0 Responses to “Scan ESX HBA’s – PowerShell’s your friend”



  1. Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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





Follow

Get every new post delivered to your Inbox.