How to retrieve Fibre Chanel WWN for ESXi Host Using PowerCLI – VirtuallyThatGuy

Imagine having to retreive several WWN for esxi rebuild or troubleshooting storage issue using the manual way? Well be my guest. This post is a quick script to retrive the WWN for esxi host in a specific cluster.

## Fibre channel WWN LIST per host

## Pass credentials if not already saved.
$cred = Get-Credential 
## Connect to vcenter
Connect-VIServer uk3p-vc01.lab.local -Credential $cred

$scope = Get-VMHost # All hosts connected in vCenter
## You can also get WWN for ESXi under specific cluster 
#$scope = Get-Cluster -Name 'UK3P-Cluster' | Get-VMHost #this will get you all the hosts under the cluster and their WWN
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
}}

## You can either export the list to csv or display in table using | ft -a

## Fibre channel WWN LIST per host

 

## Pass credentials​​ if not already saved.

$cred​​ =​​ Get-Credential​​ 

## Connect to vcenter

Connect-VIServer​​ uk3p-vc01.lab.local​​ -Credential​​ $cred

 

$scope​​ =​​ Get-VMHost​​ # All hosts connected in vCenter

## You can also get WWN for ESXi under specific cluster​​ 

#$scope = Get-Cluster -Name 'UK3P-Cluster' | Get-VMHost #this will get you all the hosts under the cluster and their WWN

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

}}

 

## You can either export the list to csv or display in table using | ft -a

​​ 

 

You May Also Like

About the Author: VirtuallyThatGuy

Leave a Reply

Your email address will not be published. Required fields are marked *