1 2 Previous Next 23 Replies Latest reply on Jan 26, 2020 6:53 PM by Narayanan_5245

    Get HBA devices/paths list with Powercli

    jxg107 Novice

      Hi Guys,

       

      I would like to know if is there a way to get the HBA devices list from a given vmHBA with PowerCli.

       

       

       

        • 1. Re: Get HBA devices/paths list with Powercli
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          Try this.

          Note it requires PowerCLI 4.1 !

          Get-VMHost | %{
               $esx = $_
               $esx | Get-VMHostHba | %{
                    $hba = $_
                    Get-ScsiLun -Hba $hba | %{
                         $row = "" | Select Host,HBA,Device
                         $row.Host = $esx.Name
                         $row.HBA = $hba.Name
                         $row.Device = $_.Extensiondata.DisplayName
                         $row
                    }
               }
          }
          

          If you need a pre-PowerCLI 4.1 version let me know

           

           

           

          ____________

          Blog: LucD notes

          Twitter: lucd22

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 2. Re: Get HBA devices/paths list with Powercli
            jxg107 Novice

            Thank you Luc,

             

            Can you make me a pre-Powercli 4.1 version?

            • 3. Re: Get HBA devices/paths list with Powercli
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              Sure, try this.

              Get-VMHost | %{
                   $esxImpl = $_
                   $esx = Get-View $esxImpl
                   $esxImpl | Get-VMHostHba | %{
                        $hba = $_
                        Get-ScsiLun -Hba $hba | %{
                             $lun = $_
                             $row = "" | Select Host,HBA,Device
                             $row.Host = $esxImpl.Name
                             $row.HBA = $hba.Name
                             $row.Device = ($esx.Config.StorageDevice.ScsiLun | where{$_.Key -eq $lun.Key} ).DisplayName
                             $row
                        }
                   }
              }
              

               

               

               

               

              ____________

              Blog: LucD notes

              Twitter: lucd22

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Get HBA devices/paths list with Powercli
                astrolab Enthusiast

                LucD.

                 

                It throws an error from:

                 

                Get-ScsiLun -Hba $hba

                 

                Value cannot be found for the mandatory parameter VmHost

                At :line:7 char:13

                +           Get-ScsiLun <<<<  $hba | %{

                 

                I don't see -hba as a valid entry following get-scsilun .

                • 5. Re: Get HBA devices/paths list with Powercli
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  Are you running PowerCLI 4.1 ?

                  Get-PowerCLIVersion
                  

                  The Get-ScsiLun cmdlet in that version has a -Hba parameter.

                   

                   

                   

                   

                  ____________

                  Blog: LucD notes

                  Twitter: lucd22

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Get HBA devices/paths list with Powercli
                    astrolab Enthusiast

                    I do now and it works. Thanks.

                    • 7. Re: Get HBA devices/paths list with Powercli
                      Butcha Enthusiast

                      LucD,

                       

                      This code is exactly what I needed recently, however it only produces the actual displayname when querying vSphere(i) 4.x hosts.........When I query classic ESX 3.5, the displayname is always null........what would be the equivalent object/property combination to query from ESX 3.5?

                      • 8. Re: Get HBA devices/paths list with Powercli
                        vmhyperv Hot Shot

                        LucD

                        Can we export the output in CSV format ? pls add the line for exporting in csv.

                         

                         

                        Thanks

                        Kumar

                        • 9. Re: Get HBA devices/paths list with Powercli
                          RvdNieuwendijk Virtuoso
                          vExpertUser Moderators

                          For ESX 3.5 the device name is in the CanonicalName property. I modified Luc's script to check for the ESX version and return the value of the CanonicalName property if the version is less than 4. I also added the export to a csv file requested by Kumar.

                           

                          Get-VMHost | ForEach-Object {
                            $esxImpl = $_
                            $esx = Get-View $esxImpl
                            $esxImpl | Get-VMHostHba | ForEach-Object {
                              $hba = $_
                              Get-ScsiLun -Hba $hba | ForEach-Object {
                                $lun = $_
                                $scsilun = $esx.Config.StorageDevice.ScsiLun | Where-Object {$_.Key -eq $lun.Key}
                                $row = "" | Select-Object -Property Host,HBA,Device
                                $row.Host = $esxImpl.Name
                                $row.HBA = $hba.Name
                                if ($esxImpl.Version.Split(".")[0] -ge 4) {
                                  $row.Device = $scsilun.DisplayName
                                }
                                else {
                                  $row.Device = $scsilun.CanonicalName
                                }                 
                                $row
                              }
                            }
                          } | Export-Csv -Path HbaDevices.csv -NoTypeInformation -UseCulture
                          
                          

                           

                          Regards, Robert

                          • 10. Re: Get HBA devices/paths list with Powercli
                            Butcha Enthusiast

                            that worked Robert!

                             

                            thanks to you and LucD for your assistance!

                            • 11. Re: Get HBA devices/paths list with Powercli
                              bmmikee01 Lurker

                              Would it be possible to list the pathing type (round robin, MRU, fixed)?  The script looks excellent but I just need to add that one column in.

                               

                              Thanks!

                              • 12. Re: Get HBA devices/paths list with Powercli
                                RvdNieuwendijk Virtuoso
                                User ModeratorsvExpert

                                Hi bmmikee01,

                                 

                                Welcome to the VMware Communities.

                                 

                                This new version of the script adds the MultipathPolicy property of the ScsiLun object to the output:

                                 

                                Get-VMHost | ForEach-Object {
                                  $esxImpl = $_
                                  $esx = Get-View $esxImpl
                                  $esxImpl | Get-VMHostHba | ForEach-Object {
                                    $hba = $_
                                    Get-ScsiLun -Hba $hba | ForEach-Object {
                                      $lun = $_
                                      $scsilun = $esx.Config.StorageDevice.ScsiLun | Where-Object {$_.Key -eq $lun.Key}
                                      $row = "" | Select-Object -Property Host,HBA,Device,MultipathPolicy
                                      $row.Host = $esxImpl.Name
                                      $row.HBA = $hba.Name
                                      if ($esxImpl.Version.Split(".")[0] -ge 4) {
                                        $row.Device = $scsilun.DisplayName
                                      }
                                      else {
                                        $row.Device = $scsilun.CanonicalName
                                      }
                                      $row.MultipathPolicy = $_.MultipathPolicy
                                      $row
                                    }
                                  }
                                } | Export-Csv -Path HbaDevices.csv -NoTypeInformation -UseCulture
                                
                                

                                 

                                Regards, Robert

                                • 13. Re: Get HBA devices/paths list with Powercli
                                  bmmikee01 Lurker

                                  Thank you very much for this, I really appreciate it.  I do have one question though, when I run I get this:

                                   

                                  Export-Csv : A parameter cannot be found that matches parameter name 'UseCulture'.  At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Mike\pathing-report.ps1:22 char:  66
                                  + } | Export-Csv -Path HbaDevices.csv -NoTypeInformation -UseCulture <<<<

                                   

                                  I was just going to remove the -UseCulture but I wasn't sure what its purpose was?

                                   

                                  Thank you again.

                                  • 14. Re: Get HBA devices/paths list with Powercli
                                    RvdNieuwendijk Virtuoso
                                    vExpertUser Moderators

                                    It looks like you are still running PowerShell version 1. If you run the PowerShell command "$Host.Version.Major" it should return 2. That will mean that you are running PowerShell v2. If it returns 1 you should upgrade to PowerShell version 2.

                                     

                                    The Export-CSV -UseCulture parameter tells PowerShell to generate the list seperator in the local culture. E.g. here in the Netherlands it is a semicolon instead of a comma. That makes it easier to open the output in Excel. Otherwise all the output will be in one Excel column.

                                    1 2 Previous Next