VMware Cloud Community
hugopeeters
Hot Shot
Hot Shot

How to correlate Datastores to LUN ID's

I am trying to retrieve a list of LUNs with the corresponding Datastores created on these luns.

My code so far:

$VIServerName = "viserver"

$VMHostName = "ESXserverFQDN"

$VIServer = Get-VIServer $VIServerName

$VMHost = Get-VMHost $VMHostName

$VMHostStorage = Get-VMHostStorage $VMHost

The properties of the $VMHostStorage object contains all the information I need, but unfortunately it lacks the correlation between the properties. The property $VMHostStorage.ScsiLun contains the LUN's and all properties I find interesting about them. The property $VMHostStorage.FileSystemVolumeInfo contains all datastores (much like the Get-Datastore command retrieves). But both these properties are unsorted arrays.

How can I find the correlation I am looking for?

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

I'm afraid we have to revert to the SDK to get that kind of info.

This script lists all vmfs filesystem defined on a specific ESX server.

And for each vmfs it lists the devicepath for each extent.

$hss = Get-View (Get-View (Get-VMHost -Name <ESX-name>).ID).ConfigManager.StorageSystem
foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
  if($mount.Volume.Type -eq "VMFS"){
    foreach($ext in $mount.Volume.Extent){
      Write-Host $mount.Volume.Name $ext.DiskName
    }
  }
}


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

ae_jenkins
Enthusiast
Enthusiast

Hey LucD. . .can this be expanded to pull in ScsiLUN information? What I'm really looking for is the path information which can show the HBA detail, and SAN path information (hex volume name).

Reply
0 Kudos
herve_warin
Contributor
Contributor

Thanks a lot, LucD, this sample is very interesting to me, but I also would be interested in the same script.

Thanks in advance.

Reply
0 Kudos
hugopeeters
Hot Shot
Hot Shot

I already found a way to get my answer. I compared the LUN path in both arrays.

See my scripting contest contribution for details.

Reply
0 Kudos
LucD
Leadership
Leadership

Does this contain what you wanted to see ?

$esxhost = <ESX-host>
$report = @()

$hss = Get-View (Get-View (Get-VMHost -Name $esxhost).ID).ConfigManager.StorageSystem
foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
  if($mount.Volume.Type -eq "VMFS"){
    foreach($ext in $mount.Volume.Extent){
      foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){
	    if($lun.Id -eq $ext.DiskName) {break}
	  }
	  foreach($path in $lun.Path){
	    $row = "" | select DSname, Pathname, PathState, PortWWN 
	    $row.DSname = $mount.Volume.Name
		$row.Pathname = $ext.DiskName
		$row.PathState = $path.PathState
		$row.PortWWN = ("{0:x}" -f $path.Transport.PortWorldWideName)
		$report += $row
	  }
    }
  }
}
$report


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

Reply
0 Kudos
ae_jenkins
Enthusiast
Enthusiast

Yes - exactly what I was looking for - thanks LucD. Sorry for the late reply: I didn't get an e-mail alert, probably because I didn't open up this discussion.

Reply
0 Kudos