VMware Cloud Community
guptatarun1989
Contributor
Contributor
Jump to solution

get count of targets, devices, and paths per hba per host with powercli 5.5

Hi all,

  I am posting this Question again in the community  as was not able to found the answer i was looking in the threads :

https://communities.vmware.com/thread/516226?start=0&tstart=0

https://communities.vmware.com/thread/293531

I went through the scripts provided for the same in the community   but seems that doesn't t work on powercli 5.5.

///

# Count targets, devices, and paths for each host

Get-Cluster $cluster | Get-VMHost | Sort-Object -Property Name | ForEach-Object {

    $VMHost = $_

    $VMHost | Get-VMHostHba -Type FibreChannel | 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

    }

}

///

I went through the LucD‌ script posted below : but that is not exactly what i am looking for .

LucD‌ : Can you please modify the same for me please.   to get count of  targets, devices, and paths per hba per host  with powercli 5.5.

//

$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

}

//

I will be grateful for any help.

Tarun Gupta

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

foreach($esx in Get-VMHost){

    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" -ErrorAction SilentlyContinue

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

        $props = [ordered]@{

            VMHost = $esx.name

            HBA = $hba.Name

            Targets = $target.Count

            Devices = $luns.Count

            Paths = $nrPaths

        }

        New-Object PSObject -Property $props

    }

}


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

foreach($esx in Get-VMHost){

    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" -ErrorAction SilentlyContinue

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

        $props = [ordered]@{

            VMHost = $esx.name

            HBA = $hba.Name

            Targets = $target.Count

            Devices = $luns.Count

            Paths = $nrPaths

        }

        New-Object PSObject -Property $props

    }

}


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

0 Kudos
guptatarun1989
Contributor
Contributor
Jump to solution

Hi Lucd,

Thanks for your reply but it is not working. When i execute it .it is giving me no output...Just an update ..yesterday night i just upgraded to powercli 6.0R3..but i hope that will not be issue.

Please help me on this .I have attached the snapshot just for reference.I also tried to export the same using Export-Csv but no output in the excel also.

targetcounts.png

Tarun Gupta

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerShell version are you using ?

Display the content of $PSVersionTable


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

0 Kudos
guptatarun1989
Contributor
Contributor
Jump to solution

Hi Lucd,

Below is the output asked.

PowerCLI D:\> $PSVersionTable

Name                           Value

----                           -----

PSVersion                      3.0

WSManStackVersion              3.0

SerializationVersion           1.1.0.1

CLRVersion                     4.0.30319.34209

BuildVersion                   6.2.9200.16398

PSCompatibleVersions           {1.0, 2.0, 3.0}

PSRemotingProtocolVersion      2.2

Thanks

Tarun Gupta

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's the right minimal version.

You do have Fibre Channel HBA I hope ?

Does the following return anything ?

Get-VMHostHba -VMHost $esx -Type "FibreChannel"


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

0 Kudos
guptatarun1989
Contributor
Contributor
Jump to solution

Thanks a Lot Lucd.

I changed the type to iscsi .

Get-VMHostHba -VMHost $esx -Type "ISCSI"


THanks a million.


Tarun Gupta


0 Kudos
ar264285
Contributor
Contributor
Jump to solution

Hi LucD,

Could you please add the  Cluster Name of Hosts, Export to CSV & LUN ID (naaid) ... It helps more to identify the Mismatch mapping details

Regards

Arun Kumar S

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No


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

0 Kudos