Script to get WWN and WWPN of hosts

                     Script to get WWN and WWPN of hosts


This Script helps VMware admins to gather the WWPN and WWPN of all the ESXi hosts quickly.


Prerequisite:-


1. Supported VMware PowerCLI Version
2. CDP should be enabled on Network Switches


How To:-

1. Run the script in VMware Powercli.
2. Save the script in .ps1 format.
3. It will prompt for the VC name against which it needs to be run, an Esxi name can also be provided, if it needs to be run against only one Esxi followed by the credentials.
4. Script is tested and safe to run.
5. Result will be saved on the C drive, if you need to save it somewhere else then please modify the last line of the script with the desired path
6. Out-put of the script will be saved in a csv format.


Code:-

$report=@()
$vc=read-host provide the vCenter Name

write-host -foregroundcolor green "Connecting to VC/ESXi" $VC
get-vc $vc

write-host -foregroundcolor green "Gathering list of all Esxi Hosts in VC" $VC
$hsts= Get-VMHostHba -vmhost * | out-nully

write-host -foregroundcolor Yellow "Gathering list of WWN/WWPN" 

for($i=0; $i -lt $hsts.count; $i++)
 {
  $data=''| Select VMhost, Device, WWN, WWPN, Type, Status, Model
  $data.vmhost=$hsts[$i].vmhost.name
  $data.type=$hsts[$i].type
  $data.Device=$hsts[$i].Device
  $data.Status=$hsts[$i].status
  $data.model=$hsts[$i].model
  $wn= "{0:x}"-f $hsts[$i].nodeworldwidename
  $pn="{0:x}" -f $hsts[$i].portworldwidename
  $data.wwn=$wn
  $data.WWpn=$pn

 $report+=$data
}

write-host -foregroundcolor yellow "Disconnecting VC" $VC
disconnect-viserver $vc -confirm:$false

write-host -foregroundcolor green "Exporting Data to file" $env:homedrive\$vc-hba.csv
$report | export-csv -path "$env:homedrive\$vc-hba.csv"


Comments