Automation

 View Only
Expand all | Collapse all

Get WWN and WWP

  • 1.  Get WWN and WWP

    Posted Aug 25, 2017 01:56 PM

    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



  • 2.  RE: Get WWN and WWP

    Posted Aug 25, 2017 02:27 PM

    Try like this

    $wwn = "200024827aaf84f2"

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



  • 3.  RE: Get WWN and WWP

    Posted Sep 21, 2017 12:30 PM

    Hi LucD,

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



  • 4.  RE: Get WWN and WWP

    Posted Sep 21, 2017 12:41 PM

    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

     



  • 5.  RE: Get WWN and WWP

    Posted Sep 21, 2017 12:52 PM

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



  • 6.  RE: Get WWN and WWP

    Posted Sep 21, 2017 12:58 PM

    Oops, I forgot the conversion to hex.

    The code above is updated



  • 7.  RE: Get WWN and WWP

    Posted Sep 21, 2017 01:15 PM

    Perfect, it work :smileyhappy:

    Thanks a lot LucD.



  • 8.  RE: Get WWN and WWP

    Posted Nov 21, 2018 06:51 PM
    This is a great Script. Is it possible to filter for HBAs that are online?


  • 9.  RE: Get WWN and WWP

    Posted Nov 21, 2018 06:58 PM

    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



  • 10.  RE: Get WWN and WWP

    Posted Nov 21, 2018 07:45 PM

    Thanks LucD,

    Works like Charm!



  • 11.  RE: Get WWN and WWP

    Posted Jan 30, 2020 01:45 PM
    Could you please suggest what does -f mean and when we use this 


  • 12.  RE: Get WWN and WWP

    Posted Jan 30, 2020 02:32 PM

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



  • 13.  RE: Get WWN and WWP

    Posted Feb 19, 2020 06:10 PM

    thank you Luc



  • 14.  RE: Get WWN and WWP

    Posted Sep 20, 2023 08:50 AM

    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



  • 15.  RE: Get WWN and WWP

    Posted Sep 20, 2023 10:44 AM

    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


  • 16.  RE: Get WWN and WWP

    Posted Oct 26, 2017 08:35 PM

    Thank you Luc. script worked perfectly!