VMware Cloud Community
jondercik2
Contributor
Contributor
Jump to solution

Connected Fibre Channel HBAs

I am trying to write a script that returns the WWNs of the two connected HBAs in all of my servers. My servers have 2 2port cards, but only 1 port on each card is physically connected. Is there a way to only return the WWNs of the active ports? Also, is there a way to see all of the properties/methods associated with an object?

I am using this script to get the inventory:

$vCenter = "vCenter"

Connect-ViServer $vCenter

$hostList = Get-VMHost -Location Datacenter | sort name

foreach($esxHost in $hostList)

{

Write-Host $esxHost.Name

$hbas = Get-View (Get-View (Get-VMHost -Name $esxHost).ID).ConfigManager.StorageSystem

foreach ($hba in $hbas.StorageDeviceInfo.HostBusAdapter)

{

if ($hba.gettype().name -eq "HostFibreChannelHba")

{

$wwn = "{0:x}" -f $hba.PortWorldWideName

Write-Host -foregroundcolor green `t $wwn

}

}

}

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can use the Status property to check which of the HBAs is active.

I also changed the script to use the Get-VMHostHba cmdlet and the new Extensiondata property that were introduced in PowerCLI 4.1.

$vCenter = "vCenter"

Connect-ViServer $vCenter

$hostList = Get-VMHost -Location Datacenter | sort name

foreach($esxHost in $hostList)
{
	Write-Host $esxHost.Name
	$hbas = Get-VMHostHba -VMHost $esxHost 
	foreach ($hba in $hbas)
	{
		if ($hba.Type -eq "FibreChannel" -and $hba.Status -eq "Online")
		{
			$wwn = "{0:x}" -f $hba.Extensiondata.PortWorldWideName
			Write-Host -foregroundcolor green `t $wwn
		}
	}

} 

To see all properties and methods on a specific object you can use the Get-Member cmdlet.

Like this for example

Get-VMHost | Get-Member

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You can use the Status property to check which of the HBAs is active.

I also changed the script to use the Get-VMHostHba cmdlet and the new Extensiondata property that were introduced in PowerCLI 4.1.

$vCenter = "vCenter"

Connect-ViServer $vCenter

$hostList = Get-VMHost -Location Datacenter | sort name

foreach($esxHost in $hostList)
{
	Write-Host $esxHost.Name
	$hbas = Get-VMHostHba -VMHost $esxHost 
	foreach ($hba in $hbas)
	{
		if ($hba.Type -eq "FibreChannel" -and $hba.Status -eq "Online")
		{
			$wwn = "{0:x}" -f $hba.Extensiondata.PortWorldWideName
			Write-Host -foregroundcolor green `t $wwn
		}
	}

} 

To see all properties and methods on a specific object you can use the Get-Member cmdlet.

Like this for example

Get-VMHost | Get-Member

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RParker
Immortal
Immortal
Jump to solution

You can use the Status property to check which of the HBAs is active.

Are you keeping an archive of these great scripts someplace on the web? If so, where can I get a link?

I don't use twitter or blog Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks.

No, I'm afraid that, beside the PowerCLI community, I don't have a repository online.

There are some, a bit more elaborate scripts, on my blog, but that's it.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jondercik2
Contributor
Contributor
Jump to solution

Thank you very much.

0 Kudos