1 2 3 Previous Next 31 Replies Latest reply on Jan 20, 2016 2:14 AM by jcayab

    powercli script to get targets devices paths from HBA

    gopinathan Enthusiast

      I need to quickly check all the hosts in my clusters to see all of them have the correct number of HBA targets, devices and paths. I can see this information in vCenter. Not an easy task if you have 100+ hosts. Does anyone have a PowerCLI script to get this info?

        • 1. Re: powercli script to get targets devices paths from HBA
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Try this

          $esx = Get-VMHost <hostname>
          
          foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){
               $target = ($hba.VMhost.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target
               $luns = Get-ScsiLun -Hba $hba  -LunType "disk"
               $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum
          
               Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths
          }
          

           

           

           

           

          ____________

          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: powercli script to get targets devices paths from HBA
            RvdNieuwendijk Virtuoso
            User ModeratorsvExpert

            The next script will give you the number of targets, devices and paths of all the HBA's of all your hosts:

             

            Get-VMHost | Sort-Object -property Name | ForEach-Object {
              $VMHost = $_
              $VMHost | Get-VMHostHba | Sort-Object -property Device | ForEach-Object {
                $VMHostHba = $_
                $ScsiLun = $VMHostHba | Get-ScsiLun
                If ($ScsiLun) {
                  $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | `
                    Where-Object {$_.Name -like "$($VMHostHba.Device)*"}
                  $Targets = ($ScsiLunPath | `
                    Group-Object -Property SanID | Measure-Object).Count
                  $Devices = ($ScsiLun | Measure-Object).Count
                  $Paths = ($ScsiLunPath | Measure-Object).Count
                }
                Else {
                  $Targets = 0
                  $Devices = 0
                  $Paths = 0
                }
                $Report = "" | Select-Object -Property VMHost,HBA,Targets,Devices,Paths
                $Report.VMHost = $VMHost.Name
                $Report.HBA = $VMHostHba.Device
                $Report.Targets = $Targets
                $Report.Devices = $Devices
                $Report.Paths = $Paths
                $Report
              }
            }
            

             

            Regards, Robert

            1 person found this helpful
            • 3. Re: powercli script to get targets devices paths from HBA
              gopinathan Enthusiast

              Thanks LucD for the quick update, and it worked. You will have to use PowerCLI 4.1. Didn't work in 4.0

              • 4. Re: powercli script to get targets devices paths from HBA
                gopinathan Enthusiast

                Thank you Robert.

                The Target and Paths were blank. The Devices reported correctly. Thanks again for the reply.

                • 5. Re: powercli script to get targets devices paths from HBA
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  For PowerCLI builds before 4.1 it only needs a small adaption.

                  $esx = Get-VMHost <hostname>
                  
                  foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){
                       $target = ((Get-View $hba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target
                       $luns = Get-ScsiLun -Hba $hba  -LunType "disk"
                       $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum
                  
                       Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths
                  }
                  

                   

                   

                   

                   

                  ____________

                  Blog: LucD notes

                  Twitter: lucd22

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: powercli script to get targets devices paths from HBA
                    RvdNieuwendijk Virtuoso
                    vExpertUser Moderators

                    My scripts works good in my environment with PowerCLI 4.1. Maybe it doesn't work with PowerCLI 4.0 or earlier. In that case you better use Luc's script.

                    • 7. Re: powercli script to get targets devices paths from HBA
                      LucD Guru
                      vExpertUser ModeratorsCommunity Warriors

                      Robert, I think the problem is with this line (I get it as well with PowerCLI 4.1).

                      $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | `
                          Where-Object {$_.Name -like "$($VMHostHba.Device)*"}
                      

                      The name of the path doesn't always start with the HBA name.

                      If you do

                      $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | `
                          Where-Object {$_.Name -like "*$($VMHostHba.Device)*"}
                      

                      or

                      $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | `
                          Where-Object {$_.Name.Contains($VMHostHba.Device)}
                      

                      your script will work, except for iScsi LUNs where the path doesn't contain the HBA name at all.

                       

                       

                       

                      ____________

                      Blog: LucD notes

                      Twitter: lucd22

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: powercli script to get targets devices paths from HBA
                        gopinathan Enthusiast

                        You guys rocks. Love the community.

                        Happy Holidays!

                        • 9. Re: powercli script to get targets devices paths from HBA
                          touimet Enthusiast

                          The script worked great! Thank you very much for this!!!

                           

                          I'm new to powershell and could use a bit of help making a small modification. I'd like to target just a cluster instead of the entire infrastructure. I am trying to get something like this working:

                           

                          foreach ($VMHost in get-cluster 

                           

                          Would anyone happen to have some ideas how to do it?

                           

                          Thanks!

                          • 10. Re: powercli script to get targets devices paths from HBA
                            RvdNieuwendijk Virtuoso
                            vExpertUser Moderators

                            Hi Todd,

                             

                            you can do the following to select only the hosts in one cluster:

                             

                            Get-Cluster <CLUSTERNAME> | Get-VMHost | Sort-Object -property Name | ForEach-Object) {
                              $VMHost = $_
                              ...
                            }
                            
                            

                             

                            Regards, Robert

                            • 11. Re: powercli script to get targets devices paths from HBA
                              touimet Enthusiast

                              Okay that worked!  However I just noticed that the original and new script does not display the Targets and Paths for an ESXi 4.0 host.  It works great on a 3.5 host.  I'm using PowerCLI 4.1.  Any ideas?

                               

                              Thanks!

                              • 12. Re: powercli script to get targets devices paths from HBA
                                lkovalio Novice

                                hi LucD & Rob

                                any updates if i run it on ESXi 5??

                                • 13. Re: powercli script to get targets devices paths from HBA
                                  LucD Guru
                                  User ModeratorsCommunity WarriorsvExpert

                                  Do you get any errors when you run it in a vSphere 5 environment ?

                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 14. Re: powercli script to get targets devices paths from HBA
                                    lkovalio Novice

                                    yes:

                                    Get-ScsiLun : 15/07/2013 09:01:01    Get-ScsiLun        Value cannot be null.

                                    Parameter name: array   

                                    At line:5 char:14

                                    +      $luns = Get-ScsiLun -Hba $hba  -LunType "disk"

                                    +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                        + CategoryInfo          : NotSpecified: (:) [Get-ScsiLun], VimException

                                        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun

                                     

                                    Get-ScsiLun : 15/07/2013 09:01:01    Get-ScsiLun        ScsiLun with luntype 'disk' was not found using the specified filter

                                    (s).   

                                    At line:5 char:14

                                    +      $luns = Get-ScsiLun -Hba $hba  -LunType "disk"

                                    +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                        + CategoryInfo          : ObjectNotFound: (:) [Get-ScsiLun], VimException

                                        + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScs

                                       iLun

                                     

                                    i guess its somthing about the EMC PowerPath

                                    please advice?

                                    1 2 3 Previous Next