This function uses everybody's favorite PowerCLI cmdlet Get-View. The speed reward: well worth it. For example:
Technique
|
Time, 28 hosts
|
Time, 270 hosts
|
Get-VMHostHba
|
61.9s
|
720s
|
Get-VMHostHBAWWN
|
1.32s
|
14.1s
|
improvement:
|
46x
|
51x
|
More than 45 times faster? I'm in. Now for the function, complete with examples in comment-based help: (double-click anywhere in the code to Select All)
function Get-VMHostHBAWWN { <# .Description Get the Port- and Node WWN(s) for HBA(s) in host(s). Feb 2012, vNugglets .Example Get-VMHostHBAWWN -VMHost myhost0.dom.com VMHostName DeviceName HBAPortWWN HBANodeWWN HBAStatus ---------- ---------- ---------- ---------- --------- myhost0.dom.com vmhba1 10:00:00:00:00:00:00:ca 20:00:00:00:00:00:00:ca online myhost0.dom.com vmhba2 10:00:00:00:00:00:00:83 20:00:00:00:00:00:00:83 online Get the HBA WWNs for hosts whose name match the pattern myhost0.dom.com .Example Get-VMHostHBAWWN -VMHost ^my.+ VMHostName DeviceName HBAPortWWN HBANodeWWN HBAStatus ---------- ---------- ---------- ---------- --------- myhost0.dom.com vmhba1 10:00:00:00:00:00:00:ca 20:00:00:00:00:00:00:ca online myhost0.dom.com vmhba2 10:00:00:00:00:00:00:83 20:00:00:00:00:00:00:83 online mytest1.dom.com vmhba1 10:00:00:00:00:00:00:da 20:00:00:00:00:00:00:da online mytest0.dom.com vmhba2 10:00:00:00:00:00:00:93 20:00:00:00:00:00:00:93 online Get the HBA WWNs for hosts whose name match the pattern ^my.+ .Example Get-Cluster mycluster | Get-VMHostHBAWWN ... Get the HBA WWNs for hosts in the cluster "mycluster" .Outputs PSCustomObject #> [CmdletBinding()]param( ## Name pattern of the host for which to get HBA info (accepts regex patterns) [parameter(Mandatory=$true,ParameterSetName="SearchByHostName")][string]$VMHostName_str, ## Name pattern of the cluster for whose hosts to get HBA info (accepts regex patterns) [parameter(Mandatory=$true,ParameterSetName="SearchByCluster",ValueFromPipelineByPropertyName)][Alias("Name")][string]$ClusterName_str ) ## end param Begin { ## helper function for formatting WWN as hex string with colon-separators function _Format-AsHexWWNString { param([parameter(Mandatory=$true)][long]$WWN_long) (("{0:x}" -f $WWN_long) -split "(\w{2})" | ?{$_ -ne ""}) -join ":" } ## end function } Process { ## params for the Get-View expression for getting the View objects $hshGetViewParams = @{ ViewType = "HostSystem" Property = "Name", "Config.StorageDevice.HostBusAdapter" } ## end hashtable Switch ($PSCmdlet.ParameterSetName) { ## if host name pattern was provided, filter on it in the Get-View expression "SearchByHostName" {$hshGetViewParams["Filter"] = @{"Name" = $VMHostName_str}; break;} ## end case ## if cluster name pattern was provided, set it as the search root for the Get-View expression "SearchByCluster" {$hshGetViewParams["SearchRoot"] = (Get-Cluster $ClusterName_str).Id; break;} } ## end switch Get-View @hshGetViewParams | Foreach-Object { $viewHost = $_ $viewHost.Config.StorageDevice.HostBusAdapter | Where-Object {$_ -is [VMware.Vim.HostFibreChannelHba]} | Foreach-Object { New-Object -TypeName PSObject -Property ([ordered]@{ VMHostName = $viewHost.Name DeviceName = $_.Device HBAPortWWN = _Format-AsHexWWNString -WWN $_.PortWorldWideName HBANodeWWN = _Format-AsHexWWNString -WWN $_.NodeWorldWideName HBAStatus = $_.Status }) ## end new-object } ## end foreach-object } ## end foreach-object } ## end process } ## end function
Not terribly fancy, but something to get it done more quickly (FaF, in fact). And, handy for other things down the road. Like, oh, using the WWN info when creating some initiator groups on your XtremIO array? What a good idea.
Oh, and if you have not yet seen/used parameter splatting, this provides a decent example of that, too -- the hashtable of parameters used on line 54. Enjoy!