1 2 3 Previous Next 31 Replies Latest reply on Jan 20, 2016 2:14 AM by jcayab Go to original post
      • 30. Re: powercli script to get targets devices paths from HBA
        weaverj Novice

        What script did you end up using?  Also looking to inventory our targets, devices, and paths before storage changes this weekend.

        • 31. Re: powercli script to get targets devices paths from HBA
          jcayab Lurker

          Hi,

           

          Some environmental info:

          ESXi and vCenter version: 5.0

          Powershell:

          Major  Minor  Build  Revision

          -----  -----  -----  --------

          4      0      -1     -1

           

          PowerCLI Version:

          VMware vSphere PowerCLI 6.0 Release 1 build 2548067

           

          I came to this same requirement. I tried to improved the codes in this thread and came up with this:

          $vCenter = Read-Host "vCenter IP "

          $outputFile = "c:\temp\FCPathCount-of-Hosts-in-$vCenter_" + (get-date -Format yyyy-MM-dd-HHmm) + ".csv"

          Connect-VIServer $vCenter

           

          $report = @()

           

          ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) { 

              ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {  

                  ForEach ($esx in ($Cluster | Get-VMhost | Sort-Object -Property Name)) { 

                      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

                              $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum

                              $row = "" | select Cluster, VMHost, vmhba, Targets, Devices, Paths

                              $row.Cluster = $Cluster.Name

                              $row.VMHost = $esx.Name

           

                              if ($hba.ExtensionData.Status -eq "online") {

                              if ($row.vmhba -eq $null) {

                                  $row.vmhba = $hba.Device

                                  $row.Targets = $target.count

                                  $row.Devices = $luns.count

                                  $row.Paths = $nrpaths

                              } elseif ($row.vmhba -eq $null) {

                                  $row.vmhba = $hba.Device

                                  $row.Targets = $target.count

                                  $row.Devices = $luns.count

                                  $row.Paths = $nrpaths

                              }

                              $report += $row

                          }

                      }

                  }

              }

          }

           

          $report | Export-Csv -Path $outputFile -NoTypeInformation -UseCulture

          1 2 3 Previous Next