VMware Cloud Community
antoniogemelli
Hot Shot
Hot Shot

Get WWN and WWP

Hello,

I check this discussion

I use this one:

$cluster = get-cluster

$hosti = get-Cluster $cluster | Get-VMHost

$report333 = @()

foreach ($esxi in $hosti) {

    $report333 +=Get-VMHosthba -VMHost $esxi -type FibreChannel |

    Select  @{N="Host";E={$esxi.Name}},

        @{N="HBA Node WWN";E={"{0:x}" -f $_.NodeWorldWideName}},

        @{N="HBA Port WWP";E={"{0:x}" -f $_.PortWorldWideName}}

    

}

$report333 | Export-csv  -Path C:\Users\gemela\Desktop\WWNTECO.csv –NoTypeInformation

And I get this format: "200024827aaf84f2","1000289et53f84f2"

Is possible to get format like: 20:00:28:22:4a:af:84:f3 10:10:28:02:4a:af:84:f2

Thanks

15 Replies
LucD
Leadership
Leadership

Try like this

$wwn = "200024827aaf84f2"

(0..7 | %{$wwn.Substring($_*2,2)}) -join ':'


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

antoniogemelli
Hot Shot
Hot Shot

Hi LucD,

Is possible to include in the script to get directly in csv file with this format?

0 Kudos
LucD
Leadership
Leadership

Try like this

$cluster = Get-Cluster

$hosti = $cluster | Get-VMHost

$report333 = foreach ($esxi in $hosti) {

    Get-VMHosthba -VMHost $esxi -type FibreChannel |

    Select  @{N="Host";E={$esxi.Name}},

        @{N='HBA Node WWN';E={$wwn = "{0:X}" -f $_.NodeWorldWideName; (0..7 | %{$wwn.Substring($_*2,2)}) -join ':'}},

        @{N='HBA Node WWP';E={$wwp = "{0:X}" -f $_.PortWorldWideName; (0..7 | %{$wwp.Substring($_*2,2)}) -join ':'}}

}

$report333 | Export-csv  -Path C:\Users\gemela\Desktop\WWNTECO.csv –NoTypeInformation

 


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

antoniogemelli
Hot Shot
Hot Shot

Script looks like works, but I got wrong WWN/WWP.

0 Kudos
LucD
Leadership
Leadership

Oops, I forgot the conversion to hex.

The code above is updated


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

antoniogemelli
Hot Shot
Hot Shot

Perfect, it work Smiley Happy

Thanks a lot LucD.

0 Kudos
falconbuban
Contributor
Contributor

Thank you Luc. script worked perfectly!

0 Kudos
Muchemi
Contributor
Contributor

This is a great Script. Is it possible to filter for HBAs that are online?
0 Kudos
LucD
Leadership
Leadership

Try like this

$cluster = Get-Cluster

$hosti = $cluster | Get-VMHost

$report333 = foreach ($esxi in $hosti) {

    Get-VMHosthba -VMHost $esxi -type FibreChannel | where{$_.STatus -eq 'online'} |

    Select  @{N="Host";E={$esxi.Name}},

        @{N='HBA Node WWN';E={$wwn = "{0:X}" -f $_.NodeWorldWideName; (0..7 | %{$wwn.Substring($_*2,2)}) -join ':'}},

        @{N='HBA Node WWP';E={$wwp = "{0:X}" -f $_.PortWorldWideName; (0..7 | %{$wwp.Substring($_*2,2)}) -join ':'}}

}

$report333 | Export-csv  -Path C:\Users\gemela\Desktop\WWNTECO.csv –NoTypeInformation


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

Muchemi
Contributor
Contributor

Thanks LucD,

Works like Charm!

Ankushsethi
Enthusiast
Enthusiast

Could you please suggest what does -f mean and when we use this 
0 Kudos
LucD
Leadership
Leadership

That is the format operator, it is used to format string output


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

0 Kudos
Ankushsethi
Enthusiast
Enthusiast

thank you Luc

0 Kudos
nikhilbabu
Contributor
Contributor

I tried the script it worked, but it didn't give me the hba name, it just gave me the wwpn, could you please help me here

0 Kudos
LucD
Leadership
Leadership

Just add the Name on the Select-Object

$cluster = Get-Cluster
$hosti = $cluster | Get-VMHost
$report333 = foreach ($esxi in $hosti) {
    Get-VMHosthba -VMHost $esxi -type FibreChannel | where{$_.Status -eq 'online'} |
    Select  @{N="Host";E={$esxi.Name}},
        Name,
        @{N='HBA Node WWN';E={$wwn = "{0:X}" -f $_.NodeWorldWideName; (0..7 | %{$wwn.Substring($_*2,2)}) -join ':'}},
        @{N='HBA Node WWP';E={$wwp = "{0:X}" -f $_.PortWorldWideName; (0..7 | %{$wwp.Substring($_*2,2)}) -join ':'}}
}

$report333 | Export-csv  -Path C:\Users\gemela\Desktop\WWNTECO.csv –NoTypeInformation


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

0 Kudos