Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

Try like this

$dsTab = @{}

foreach($ds in (Get-Datastore | where{$_.ExtensionData.Summary.MultipleHostAccess})){

    $ds.ExtensionData.Info.Vmfs.Extent | %{

        if($_.DiskName){

            $dsTab.Add($_.DiskName,$ds.Name)

        }

    }

}

foreach ($esx in Get-VMHost){

    $adapterTab = @{}

    $pathTab = @{}

    $lunTab = @{}

    $rdmTab = @{}

    $esx.ExtensionData.Config.StorageDevice.HostBusAdapter | %{

        $adapterTab.Add($_.Key,$_.Device)

    }

    $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | %{

        $pathTab.Add($_.Lun,$_.Path.Name)

    }

    $esx.ExtensionData.Config.StorageDevice.ScsiLun | %{

        $lunTab.Add($_.Key,$_.CanonicalName)

    }

    foreach($rdm in (Get-VM -Location $esx | Get-HardDisk -DiskType RawPhysical,RawVirtual)){

        if($rdm){

            $rdmTab.Add($rdm.ScsiCanonicalName,@{

                                            VM = $rdm.Parent.Name

                                            HD = $rdm.Name

                                          })

         }

    }

    foreach($adapter in $esx.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter){

        foreach($target in $adapter.Target){

            foreach($lun in $target.Lun){

                $lun | Select @{N='ESX';E={$esx.Name}},

                            @{N='Adapter';E={$adapterTab[$adapter.Adapter]}},

                            @{N='Canonical';E={$lunTab[$lun.ScsiLun]}},

                            @{N='Path';E={$pathTab[$lun.ScsiLun]}},

                            Lun,

                            @{N='Datastore';E={$dsTab[$lunTab[$lun.ScsiLun]]}},

                            @{N='RDM';E={"$($rdmTab[$lunTab[$lun.ScsiLun]].VM) $($rdmTab[$lunTab[$lun.ScsiLun]].HD)"}}

            }

        }

    }

}


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

View solution in original post