VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get vCenter, Cluster, Host and LUN ID in the output

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I was referring LUN ID or LUN number to below screenshot

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try replacing that line with

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


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked....Thank you LucD.

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked Perfectly. Thank you very much Smiley Happy

0 Kudos