VMware Cloud Community
qwert1235
Enthusiast
Enthusiast
Jump to solution

Get LUN info from ESX host

Hello:

Is there a way to extract LUNs info from ESX host?  I need LUN(s) number/ID in order to match it with ID storage admin is seeing...

Thanks a lot!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Sure, simplest way is like this

$report = foreach($esx in Get-VMHost){
    foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){
        if($hbaKey.Target){
            foreach($tgtKey in $hbaKey.Target){
                foreach($lunKey in $tgtKey.Lun){
                    $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}
                    $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}
                    Select-Object -InputObject $lun -Property @{N="Host";E={$esx.Name}},
                        @{N="HBA";E={$hba.Device}},
                        CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}
                }
            }
        }
    }
} 
$report | Export-Csv "C:\lun-report.csv" -NoTypeInformation -UseCulture 


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

View solution in original post

Reply
0 Kudos
11 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can use the Get-ScsiLun cmdlet to extract LUN info from ESX hosts.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
qwert1235
Enthusiast
Enthusiast
Jump to solution

I think Get-SCSI LUN is very close, but I still do not see the LUN ID.

I run

Get-VMHost -Name "hostname" | Get-ScsiLun

and got the result:

Id                   : HostSystem-host-65635/vmhba1:1:1

CanonicalName        : vmhba1:1:1

RuntimeName          :

Key                  : key-vim.host.ScsiDisk-vmhba1:1:1

LunType              : disk

Model                : SYMMETRIX     

SerialNumber         : unavailable

Vendor               : EMC

ConsoleDeviceName    : /vmfs/devices/disks/vml.02000100006006048000019010420153303030393453594d4d4554

CapacityMB           : 276210

MultipathPolicy      : Fixed

CommandsToSwitchPath : 50

BlocksToSwitchPath   : 2048

HostId               : HostSystem-host-65635

VMHostId             : HostSystem-host-65635

VMHost               : ID = HostSystem-host-65635

Uid                  : /VIServer=email@hostname:443/VMHost=HostSystem-host-65635/ScsiLun=vmhba1:1:

                       1/

ExtensionData        : VMware.Vim.HostScsiDisk

But here is still no info regarding LUN ID that I can see (match) on storage side.

How can I get just LUN ID info for all datastores on my hosts?

Thanks!

Reply
0 Kudos
a_p_
Leadership
Leadership
Jump to solution

Best bet in cases like this is to google for s.th. like get-scsilun canonicalname lucd Smiley Wink

Mabye this helps:

http://communities.vmware.com/thread/315049

André

LucD
Leadership
Leadership
Jump to solution

What exactly do you mean with LUN ID ?

Do you see the value in the vSphere client ? Is it one of these ?

lunId.png


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

LucD
Leadership
Leadership
Jump to solution

Lol :smileylaugh:


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

Reply
0 Kudos
qwert1235
Enthusiast
Enthusiast
Jump to solution

the issue is that this VC 2.5 with ESX 3.5...

refering to your picture, I am looking for Identifier (last 3 characters, like 09c, 279, 199, on your picture) and have to match it with Datastores names.

I run your script and for canonical name I have something like vmhba1:1:16, but not naa.60060160d2c82200f2addfa66c2cdf11 like I hoped to see.

Is it possible to get this info from 3.5 hosts?

Thanks a lot!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

We can try, back to the old-fashioned way of doing this.

Try this

foreach($esx in Get-VMHost){
    foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){
        if($hbaKey.Target){
            foreach($tgtKey in $hbaKey.Target){
                foreach($lunKey in $tgtKey.Lun){
                    $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}
                    $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}
                    Select-Object -InputObject $lun -Property @{N="Host";E={$esx.Name}},
                        @{N="HBA";E={$hba.Device}},
                        CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}
                }
            }
        }
    }
}

Does it return the information you're after ?


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

Reply
0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Wow this is cool LucD

thanks for sharing it here with us.

how to export it to CSV, where should I put the Export-CSV comamnd in ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, simplest way is like this

$report = foreach($esx in Get-VMHost){
    foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){
        if($hbaKey.Target){
            foreach($tgtKey in $hbaKey.Target){
                foreach($lunKey in $tgtKey.Lun){
                    $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}
                    $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}
                    Select-Object -InputObject $lun -Property @{N="Host";E={$esx.Name}},
                        @{N="HBA";E={$hba.Device}},
                        CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}
                }
            }
        }
    }
} 
$report | Export-Csv "C:\lun-report.csv" -NoTypeInformation -UseCulture 


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

Reply
0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Cool, many thanks for the reply Luc.

With your presence here the Powershell is now well known in IT wirld.

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
qwert1235
Enthusiast
Enthusiast
Jump to solution

Luc,

Thanks a lot!

Reply
0 Kudos