PowerCLI

 View Only
  • 1.  How to get the below screenshot information using powercli

    Posted Jun 10, 2024 10:29 AM

    How to get the below screenshot information using powercli

    I would like to get the host and its path details 



  • 2.  RE: How to get the below screenshot information using powercli

    Posted Jun 10, 2024 11:35 AM

    Try something like this

    Get-Cluster -PipelineVariable cluster |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $hba = Get-VMHostHba -VMHost $esx
        $lun = Get-ScsiLun -VmHost $esx
        $path = Get-ScsiLunPath -ScsiLun $lun
        New-Object -TypeName PSObject -Property ([ordered]@{
                Cluster = $cluster.Name
                VMHost = $esx.Name
                Adapters = $esx.ExtensionData.Config.StorageDevice.HostBusAdapter.Count
                Targets = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun.Path.Count
                'Attached Devices' = $esx.ExtensionData.Config.StorageDevice.ScsiLun.where{$_.OperationalState -eq 'ok'}.Count, $esx.ExtensionData.Config.StorageDevice.ScsiLun.Count -join ' of '
                'Active Paths' = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun.Path.Where{$_.PathState -eq 'active'}.Count
                Datastores = (Get-Datastore -RelatedObject $esx).Count
            })
    }


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


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


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



  • 3.  RE: How to get the below screenshot information using powercli

    Posted Jun 11, 2024 04:51 AM

    Hi LucD,

    I am able to get the output but Targets are showing active path count. it should be target count as 4 or 5. 




  • 4.  RE: How to get the below screenshot information using powercli

    Posted Jun 11, 2024 05:31 AM

    Try like this

    Get-Cluster -PipelineVariable cluster |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        New-Object -TypeName PSObject -Property ([ordered]@{
                Cluster = $cluster.Name
                VMHost = $esx.Name
                Adapters = $esx.ExtensionData.Config.StorageDevice.HostBusAdapter.Count
                Targets = ($esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Group-Object -Property Id).Count
                'Attached Devices' = $esx.ExtensionData.Config.StorageDevice.ScsiLun.where{ $_.OperationalState -eq 'ok' }.Count, $esx.ExtensionData.Config.StorageDevice.ScsiLun.Count -join ' of '
                'Active Paths' = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun.Path.Where{ $_.PathState -eq 'active' }.Count
                Datastores = (Get-Datastore -RelatedObject $esx).Count
            })
    }


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


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


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



  • 5.  RE: How to get the below screenshot information using powercli

    Posted Jun 11, 2024 08:41 AM

    Hi LucD,

    it now showing the attached devices count not the target. in my case, I have 5 targets in GUI




  • 6.  RE: How to get the below screenshot information using powercli

    Posted Jun 11, 2024 08:41 AM

    Hi LucD,

    Still I am getting the active path numbers not the targets, in my case, I see targets are 5 in GUI




  • 7.  RE: How to get the below screenshot information using powercli
    Best Answer

    Posted Jun 11, 2024 12:32 PM

    Check with this one

    Targets =($esx.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter.Target | Measure-Object).Count


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


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


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



  • 8.  RE: How to get the below screenshot information using powercli

    Posted Jun 12, 2024 02:44 AM

    Thank you very much LucD. That worked perfectly :)