PowerCLI

 View Only
  • 1.  Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 11:49 AM

    Hi,

    Please help, how can I get the vCenter, Cluster, Host and LUN ID in the output.

    Please help.

    Script

    $clusterName = 'Compute'

    $report = foreach($esx in (Get-Cluster -Name $clusterName | Get-VMHost)){

        $esxcli = Get-EsxCli -VMHost $esx -V2

        $esxcli.storage.vmfs.extent.list.invoke() | %{

            $obj = $esxcli.storage.core.device.list.CreateArgs()

            $obj.device = $_.DeviceName

            $esxcli.storage.core.device.list.Invoke($obj)

            $esxcli.system.hostname.get()

        }

    }

    $report | Select Device,Size,NoofoutstandingIOswithcompetingworlds | ft -auto



  • 2.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 12:08 PM

    Not sure what you mean by "LUN Id"?

    The other properties can be added like this

    $clusterName = 'Compute'

    $report = @()


    Get-Cluster -Name $clusterName -PipelineVariable cluster |

    Get-VMHost -PipelineVariable esx |

    ForEach-Object -Process {

        $esxcli = Get-EsxCli -VMHost $esx -V2


        $esxcli.storage.vmfs.extent.list.invoke() | %{

            $obj = $esxcli.storage.core.device.list.CreateArgs()

            $obj.device = $_.DeviceName

            $esxcli.storage.core.device.list.Invoke($obj) |

            ForEach-Object -Process {

                $report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |

                    Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |

                    Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru

            }

        }

    }

    $report | Select Device,Size,NoofoutstandingIOswithcompetingworlds | ft -auto



  • 3.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 12:16 PM

    LucD,

    I was referring LUN ID or LUN number to below screenshot



  • 4.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 12:26 PM

    Try like this

    $clusterName = 'Compute'

    $report = @()


    Get-Cluster -Name $clusterName -PipelineVariable cluster |

    Get-VMHost -PipelineVariable esx |

    ForEach-Object -Process {

        $esxcli = Get-EsxCli -VMHost $esx -V2


        $esxcli.storage.vmfs.extent.list.invoke() | %{

            $obj = $esxcli.storage.core.device.list.CreateArgs()

            $obj.device = $_.DeviceName

            $path = $esxcli.storage.core.path.list.Invoke($obj)

            $esxcli.storage.core.device.list.Invoke($obj) |

            ForEach-Object -Process {

                $report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |

                    Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |

                    Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru |

                    Add-Member -MemberType NoteProperty -Name LUN -Value $path.LUN -PassThru

            }

        }

    }

    $report | Select Device,Size,NoofoutstandingIOswithcompetingworlds | ft -auto



  • 5.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 12:37 PM

    LucD,

    Now, I am seeing the LUN number or ID but it is showing multiple times as below

    {253, 253, 253, 253}

    vCenter        Cluster     VMHost         LUN                  Device                               Size    DeviceMaxQueueDepth NoofoutstandingIOswithcompetingworlds
    -------        -------     ------         ---                  ------                               ----    ------------------- -------------------------------------
    10.10.10.12 Compute   10.10.11.11 {253, 253, 253, 253} naa.60024xxxxxxxxxxxxxxxxxxxxxxxxxxx 5120    128                 128

    vCenter        Cluster     VMHost         LUN                  Device                               Size    DeviceMaxQueueDepth NoofoutstandingIOswithcompetingworlds
    -------        -------     ------         ---                  ------                               ----    ------------------- -------------------------------------
    172.25.255.176 AUR-Compute 172.25.255.112 {253, 253, 253, 253} naa.624a9370427be350aef744380001101b 5120    128                 128



  • 6.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 12:39 PM

    Try replacing that line with

                    Add-Member -MemberType NoteProperty -Name LUN -Value (($path.LUN | Sort-Object -Unique) -join '|') -PassThru


  • 7.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 12:51 PM

    That worked....Thank you LucD.

    One last thing, is there a way to get the datastore name using the naa in this script?



  • 8.  RE: Get vCenter, Cluster, Host and LUN ID in the output
    Best Answer

    Posted Jul 28, 2020 01:18 PM

    You could do something like this

    $clusterName = 'Compute'

    $report = @()


    Get-Cluster -Name $clusterName -PipelineVariable cluster |

    Get-VMHost -PipelineVariable esx |

    ForEach-Object -Process {

        $esxcli = Get-EsxCli -VMHost $esx -V2


        $esxcli.storage.vmfs.extent.list.invoke() | %{

            $obj = $esxcli.storage.core.device.list.CreateArgs()

            $obj.device = $_.DeviceName

            $path = $esxcli.storage.core.path.list.Invoke($obj)

            $esxcli.storage.core.device.list.Invoke($obj) |

            ForEach-Object -Process {

                $dev = $_

                $ds = (Get-Datastore -RelatedObject $esx) |

                    where{$_.ExtensionData.Info.Vmfs.Extent.diskname -contains $dev.Device}

                $report += Add-Member -InputObject $_ -MemberType NoteProperty -Name vCenter -Value (([uri]$esx.ExtensionData.Client.ServiceUrl).Host) -PassThru |

                    Add-Member -MemberType NoteProperty -Name Cluster -Value $cluster.Name -PassThru |

                    Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru |

                    Add-Member -MemberType NoteProperty -Name Datastore -Value $ds.Name -PassThru |

                    Add-Member -MemberType NoteProperty -Name LUN -Value (($path.LUN | Sort-Object -Unique) -join '|') -PassThru

                  

            }

        }

    }

    $report | Select Device,Size,NoofoutstandingIOswithcompetingworlds | ft -auto



  • 9.  RE: Get vCenter, Cluster, Host and LUN ID in the output

    Posted Jul 28, 2020 01:28 PM

    That worked Perfectly. Thank you very much :smileyhappy: