VMware Cloud Community
Benomatic
Contributor
Contributor
Jump to solution

Link Datastore Name with ConsoleDeviceName and CanonicalName

Hi Folks,

I would like to link 3 parameters, ConsoleDeviceName, CanonicalName and "Datastore Name".

The twice first (ConsoleDeviceName, CanonicalName) can i get with "Get-VMHost "MyESXHost" | Get-ScsiLun"

but how can I get the Datastore Name ?

7964_7964.png

thanks for help

Reply
0 Kudos
1 Solution

Accepted Solutions
ykalchev
VMware Employee
VMware Employee
Jump to solution

Hi,

In order to get datastore name for each lun you need to examine disk extent information for each datastore attached to the host and link them using lun cannonical names. VMFS datastore disk extent information is available in HostScsiDiskPartition object. Here is an example code how to do that:

$h = Get-VMhost "MyESXHost"

# collect VMFS datastore name and extent cannonical names into a hashtable
$dsLunList = @{}
$dsView = $h | Get-Datastore | ? {$_.Type -eq "VMFS"} | Get-View 
foreach ($ds in $dsView) {
	foreach ($diskExtent in $ds.Info.Vmfs.Extent) {
		$dsLunList[http://$diskExtent.DiskName|http://$diskExtent.DiskName] = $ds.Info.Name
	}
} 

#populate datastore name for each lun if available
$lunList = @()
$h | Get-ScsiLun | % {
	$lun = "" | select ConsoleDeviceName, CanonicalName, DatastoreName
	$lun.ConsoleDeviceName = $_.ConsoleDeviceName
	$lun.CanonicalName = $_.CanonicalName
	
	if ($dsLunList.ContainsKey($_.CanonicalName)) {
		$lun.DatastoreName = $dsLunList[http://$_.CanonicalName|http://$_.CanonicalName]
	}
	
	$lunList += $lun
}

$lunList

Regards,

Yasen

Yasen Kalchev, vSM Dev Team

View solution in original post

Reply
0 Kudos
2 Replies
ykalchev
VMware Employee
VMware Employee
Jump to solution

Hi,

In order to get datastore name for each lun you need to examine disk extent information for each datastore attached to the host and link them using lun cannonical names. VMFS datastore disk extent information is available in HostScsiDiskPartition object. Here is an example code how to do that:

$h = Get-VMhost "MyESXHost"

# collect VMFS datastore name and extent cannonical names into a hashtable
$dsLunList = @{}
$dsView = $h | Get-Datastore | ? {$_.Type -eq "VMFS"} | Get-View 
foreach ($ds in $dsView) {
	foreach ($diskExtent in $ds.Info.Vmfs.Extent) {
		$dsLunList[http://$diskExtent.DiskName|http://$diskExtent.DiskName] = $ds.Info.Name
	}
} 

#populate datastore name for each lun if available
$lunList = @()
$h | Get-ScsiLun | % {
	$lun = "" | select ConsoleDeviceName, CanonicalName, DatastoreName
	$lun.ConsoleDeviceName = $_.ConsoleDeviceName
	$lun.CanonicalName = $_.CanonicalName
	
	if ($dsLunList.ContainsKey($_.CanonicalName)) {
		$lun.DatastoreName = $dsLunList[http://$_.CanonicalName|http://$_.CanonicalName]
	}
	
	$lunList += $lun
}

$lunList

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
Reply
0 Kudos
Benomatic
Contributor
Contributor
Jump to solution

Big Thanks ! Yasen, that is what I want

Reply
0 Kudos