VMware

This Question is Answered

2 "helpful" answers available (6 pts)
3 Replies Last post: Nov 10, 2009 9:51 AM by sylvain82  

how to get a Lun number from StorageDeviceInfo property to match a DeviceName or DevicePath? posted: Nov 6, 2009 6:35 AM

Click to view sylvain82's profile Novice 7 posts since
Dec 21, 2007

Hello,

I'm new in powershell script and I have a basic question. I try to get a LUN Number from a disk connected to an ESX server. I want this because I want to add a rdm disk to a VM but in vsphere we have to specify the device name which is unique. So to easily identify the rdm LUN I want to match the LUN Number with the device name in the property StorageDeviceInfo.

Is anyone know a easy way to do that?

Thank you

Sylvain

Click to view LucD's profile Champion 2,437 posts since
Oct 31, 2005
The following script produces a report with the information you require (I think).
$hostStor = Get-VMHost <ESX-hostname> | Get-VMHostStorage | Get-View

$hba = @{}
$hostSTor.StorageDeviceInfo.HostBusAdapter | %{
	$hba[http://$_.Key|http://$_.Key] = $_
}
$lun = @{}
$hostSTor.StorageDeviceInfo.ScsiLun | %{
	$lun[http://$_.Key|http://$_.Key] = $_
}

$report = @()
$hostStor.StorageDeviceInfo.ScsiTopology.Adapter | %{
	$hbaDevice = $hba[http://$_.Adapter|http://$_.Adapter].Device
	$_.Target | %{
		$targetNumber =  $_.Target
		$_.Lun | %{
			$row = "" | Select hbaDevice, targetNumber, lunNumber, lunDeviceName
			$row.hbaDevice = $hbaDevice
			$row.targetNumber = $targetNumber
			$row.lunNumber = $_.Lun
			$row.lunDeviceName = $lun[http://$_.ScsiLun|http://$_.ScsiLun].DeviceName
			$report += $row
		}
	}
}
$report

Since there are some square brackets in the script I attached the script as a file as well.
Attachments:

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities