There are several ways to get HBA WWNs on VMware vSphere ESX/ESXi host:
1. Connect to a server or vCenter, open server Configuration tab, under Hardware select Storage Adapters:
You can also copy WWNN (World Wide Node Name) and WWPN (World Wide Port Name)
2. How to find HBA WWN via ESXi Shell / CLI:
VMware vSphere ESXi 5.0+:
~ # esxcli storage core adapter list HBA Name Driver Link State UID Description -------- ------------ ---------- ------------------------------------ ------------------------------------------------------------ vmhba0 megaraid_sas link-n/a unknown.vmhba0 (0:1:0.0) LSI / Symbios Logic MegaRAID SAS SKINNY Controller vmhba1 fnic link-up fc.20000025b5020110:20000025b502a121 (0:8:0.0) Cisco Systems Inc Cisco VIC FCoE HBA Driver vmhba2 fnic link-up fc.20000025b5020110:20000025b502a120 (0:9:0.0) Cisco Systems Inc Cisco VIC FCoE HBA Driver
VMware ESX/ESXi 2.1.0 – 4.1.x:
~ # esxcfg-scsidevs -a vmhba0 megaraid_sas link-n/a unknown.vmhba0 (0:1:0.0) LSI / Symbios Logic MegaRAID SAS SKINNY Controller vmhba1 fnic link-up fc.20000025b5020110:20000025b502a121 (0:8:0.0) Cisco Systems Inc Cisco VIC FCoE HBA Driver vmhba2 fnic link-up fc.20000025b5020110:20000025b502a120 (0:9:0.0) Cisco Systems Inc Cisco VIC FCoE HBA Driver
OR
- Connect to ESXi shell either via putty/SSH or DCUI (Direct Console User Interface) / server console
- Run ‘ls /proc/scsi/‘ and check the folder names:
~ # ls /proc/scsi/ mptsas qla2xxx
- Look for a folder like ‘qla2xxx‘ – QLogic HBA, ‘lpfc820‘ – Emulex HBA, ‘bnx2i” – Brocade HBA;
- Run ‘ls /proc/scsi/qla2xxx’. You will get a list of files, named by a number. Each file contains information about one HBA;
~ # ls /proc/scsi/qla2xxx/ 6 7
- Now run ‘cat /proc/scsi/qla2xxx/6‘ to get full info on the HBA. Alternatively, run the following commands:
- Run ” cat /proc/scsi/qla2xxx/6 | grep -A3 ‘SCSI Device Information:’ ” to get WWNN and WWPNs:
~ # cat /proc/scsi/qla2xxx/6 | grep -A3 'SCSI Device Information:' SCSI Device Information: scsi-qla0-adapter-node=20000024ff31f0c8:000000:0; scsi-qla0-adapter-port=21000024ff31f0c8:000000:0;
- Run ” cat /proc/scsi/qla2xxx/6 | grep ‘Host Device Name’ ” to get vmhba number:
~ # cat /proc/scsi/qla2xxx/6 | grep 'Host Device Name' Host Device Name vmhba3
- Run ” cat /proc/scsi/qla2xxx/6 | grep -A3 ‘SCSI Device Information:’ ” to get WWNN and WWPNs:
3. Powershell script to list host name, vmhba number, HBA model / driver and World Wide Port Name (WWN):
$scope = Get-VMHost # All hosts connected in vCenter #$scope = Get-Cluster -Name 'MyCluster' | Get-VMHost # All hosts in a specific cluster foreach ($esx in $scope){ Write-Host "Host:", $esx $hbas = Get-VMHostHba -VMHost $esx -Type FibreChannel foreach ($hba in $hbas){ $wwpn = "{0:x}" -f $hba.PortWorldWideName Write-Host `t $hba.Device, "|", $hba.model, "|", "World Wide Port Name:" $wwpn }}
Result:
Host: ESXi5-001.vstrong.info vmhba1 | Cisco VIC FCoE HBA Driver | World Wide Port Name: 20000025b502a101 vmhba2 | Cisco VIC FCoE HBA Driver | World Wide Port Name: 20000025b502a100
~ # esxcfg-scsidevs -a
Thank you. You can also run “esxcli storage core adapter list” on vSphere ESXi 5.0+. I updated the post with a new info.
Connect-VIServer -Menu
$vmHost = Get-VMHost
$vmHost | Get-VMHostHba -Type FibreChannel | Select VMHost,Name,Pci,Driver, PortWorldWideName, @{name=”WWN”;Expression={“{0:x}” -f $_.PortWorldWideName}} |FT -Auto
$vmHost =”
Disconnect-VIServer
What does {0:x} -f do? (I mean, I see that it formats the WWPN properly, but how does it do it?)
Here is some light reading:
https://devcentral.f5.com/articles/powershell-abcs-f-is-for-format-operator#.UwyG7YX0bLg
3. Powershell script to list host name, vmhba number, HBA model / driver and World Wide Port Name (WWN):
Hello Guys,
can you please modifiy this script to get all info in excel sheet.
#===============================================================================================
# Parameter Definitions
#===============================================================================================
Param
(
# Enter vCenter Name
[Parameter(Mandatory=$True)]
[string]$vCenterName,
# Input the ClusterName, you may enter multiple, e.g “Cluster1″,”Cluster2″,”Cluster3”
[Parameter(Mandatory=$True)]
[String[]]$sClusterName
)
#===============================================================================================
# Function Definitions
#===============================================================================================
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
function Get-StorageAdapters
{
# If the provided cluster name cannot be found, script will stop and disconnected from vCenter
$aCluster = Get-cluster $sClusterName
if(!$aCluster)
{
throw{“Error! Unable to find cluster: $sClusterName”}
If ($oVI)
{
Write-host “Disconnecting from vCenter $vCenterName”
disconnect-viserver * -confirm:$false
}
}
# Get all associated hosts to the cluster and place in an array
$arrayESXHosts = @(Get-cluster $sClusterName | Get-VMHost)
# Count how many hosts are in the array and loop that many times to get their storage info.
$countHosts = $arrayESXHosts.count
for($i = 0; $i -lt $countHosts; $i++)
{
$esxHost = $arrayESXHosts[$i]
Write-Host “Working on Host: “, $esxHost`n
$aHBAs = Get-VMHostHba -VMHost $esxHost -Type FibreChannel
foreach ($HBA in $aHBAs)
{
$WWPN = “{0:x}” -f $HBA.PortWorldWideName
#$WWN = $HBA.WorldWideName
$Device = $HBA.Device
$Model = $HBA.model
$WWPName = $WWPN
$out = new-object psobject
$out | Add-Member noteproperty “ESX Host” $esxHost
$out | Add-Member noteproperty “HBA Device” $Device
$out | Add-Member noteproperty “HBA Model” $Model
$out | Add-Member noteproperty “World Wide Port Name” $WWPName
#$out | Add-Member noteproperty “World Wide Name” $WWN
# For each host, an individual spreadsheet will be created with their data
$array = @()
$array += $out
$array | Export-CSV “$sScriptPathStorage_Adapters$i.csv” -notype
}
}
# For each hosts’ spreadsheet that were created, import back to PowerShell variable CSV
for($i=0; $i -lt $countHosts; $i++){
$CSV += @(Import-CSV “$sScriptPathStorage_Adapters$i.csv”)
}
# Export all spreadsheet that were imported to variable CSV to a single spreadsheet
$CSV | Export-CSV “$sScriptPathStorage_Adapters.csv” -notype
# Remove all of the individual spreadsheets that were created for each hosts
for($i=0; $i -lt $countHosts; $i++){
Remove-Item “$sScriptPathStorage_Adapters$i.csv”
}
}
#===============================================================================================
# Begin Main
#===============================================================================================
Write-Host “Begin Main”
# Load the Powercli snapin
If(!(Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue))
{
Write-host “Adding VMware Snappin”
Add-PSSnapin VMware.VimAutomation.Core
}
TRY
{
# Connect to VCenter Server
Write-Host “Connecting to vCenter $vCenterName`n”
$oVI = connect-viserver $vCenterName -Port 443 -ErrorVariable Err -ErrorAction stop
}
CATCH
{
throw (“!!!Error: Unable to connect to vCenter Server: $vCenterName!!!”)
}
# Calls the function Get-ScriptDirectory
$sScriptPath = Get-ScriptDirectory
# calls the main function, which will get the storage adapter WWN, Device, and Model
Get-StorageAdapters
# If vCenter is still connected, disconnect all
If ($oVI)
{
Disconnect-Viserver * -confirm:$false
Write-Host “Disconnected from the vCenter Server: $vCenterName”
}
Hi Abdel,
I checked in our production environments is workign perfectly fine. I really appreciate you.
Hi All,
In our prod environment we are using EMC and Netapp storage in VMware environment. so we are planning to decommission EMC storage and using only Netapp.
I need powercli scripts to get any VMs that are not on Netapp storage. so that we will plan to moving the VMs to new Netapp datastore.
Hi All,
I need powercli scripts to get ssh services status on all esxi host in excel sheet.
Hello,
Could you please help me to get 30 Days all VM snapshot deleted auto ?
Worked for me. Thanks a lot!