PeetersOnline.nl
Translate Vml to LUN Path with Powershell
While checking the vmkernel logs on our VMware ESX Servers today, I ran into some errors referencing luns using a vml string. It looks something like this: vml.827149017315617. I would like to know what lun this error is referencing, but I prefer the LUN Path notation, e.g.: vmhba1:2:137. So I wrote this Powershell VI Toolkit function that can translate the vml into the lun path:
# Function: Translate a VML (e.g.: vml.9364839746917650) to a Lun Path (e.g.: vmhba1:2:137) function Translate-VmlToLunPath { param( [string]$VMHostName, [string]$Vml ) Return (Get-VMHost $VMhostName | Get-ScsiLun | Where {$_.ConsoleDeviceName -match $Vml}).CanonicalName } |
Feed it a host name and a vml string and it will return the lun path. Here’s an example script that uses this function when looking for LUNs with SCSI Reservation Errors:
# Example use in a script: Get LUNs with SCSI Reservation Conflicts $VIServerName = "myVIServer" $NumLines = 1000 $VC = Connect-VIServer $VIServerName ForEach ($VMHost in Get-VMHost) { ForEach ($Log in ($VMHost | Get-Log -Key vmkernel -NumLines $NumLines)) { $MatchedEntries = $Log.Entries | Where {$_ -match "reservation" -and $_ -match "vml.\d*"} ForEach ($VmlId in $matches.values) { $myObj = "" | Select VMHost, ErrorLun $myObj.VMHost = $VMHost.Name $myObj.ErrorLun = Translate-VmlToLunPath -VMHostName $VMHost.Name -Vml $VmlId Return $myObj } } } Disconnect-VIServer -Confirm:$False |
Enjoy!
Hugo
3 Responses to Translate Vml to LUN Path with Powershell
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





Hi Hugo, when I try to run your script, I am receiving this error message:
Get-Log : 8/27/2009 10:58:52 AM Get-Log A2618ED6-5613-4F05-9693-DF51274B582B A general system error occurred:
At C:\Users\test\Documents\SysAdmin\Scripts\VMware Scripts\getscsireservationerrors.ps1:8 char:37
+ ForEach ($Log in ($VMHost | Get-Log <<<< -Key vmkernel -NumLines $NumLines))
+ CategoryInfo : NotSpecified: (:) [Get-Log], ViRuntimeException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_GetSingleLog_ViError,VMware.VimAutomation.Commands.GetLog
Any idea what is going on here?
It appears the Get-Log cmdlet is causing a general system error. Are you sure you have permissions to read the logfiles on the ESX server? I wouldn’t know what else could be wrong.
Hugo
It’s a ESXi server, therefore vmkernel logs do not exists? When I change vmkernel to messages the get-log commando itself works.