A few months ago I noticed a link to this awesome article titled: NAA id’s and breaking them apart, which dissects the NAA identifiers that you see in the vSphere client when looking at storage devices. Recently I was working with my storage admin — I was seeing a 2.81MB device on all of the hosts in a cluster that he had not specifically presented. Unfortunately I had no good way to tell him exactly which device I was seeing. I then remembered and found this article and was able to convert the NAA ID to the VMAX device ID using the key described in the article. While converting this device ID by hand, I thought…wouldn’t it be nice if I could just paste in the NAA ID and automatically convert it to the device ID? I threw together a quick powershell function that does just that:
[cc lang=”powershell”]
Function Convert-NaaIdToVmaxDeviceId ($naa) {
# http://vmwise.com/2012/06/01/naa-ids-and-breaking-them-apart/
if ($naa.length -ne 36) { “NAA value must be 36 characters”; break }
$deviceString = $naa.ToCharArray()
$device = [char][Convert]::ToInt32(“$($deviceString[26])$($deviceString[27])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[28])$($deviceString[29])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[30])$($deviceString[31])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[32])$($deviceString[33])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[34])$($deviceString[35])”, 16)
return $device
}
[/cc]
The function expects just one parameter and can be used like this:
Convert-NaaIdToVmaxDeviceId "naa.60000970000000000000533031363641"
Just FYI for those adverse to CLI, EMC has a free plug-in to the vSphere Client that will do this for you. It is called Virtual Storage Integrator and can be found here:
http://powerlink.emc.com/km/live1/en_US/Offering_Technical/Software_Download/emc-vsi-sv-5.3.0-vmware-vsphere-WINDOWS-x86.zip
Not only will it provide the device ID, but also list out things such as RAID, device type (thin, thick), thin pool(s), metavolume configuration, etc.
Very cool, thanks.
Is there a way to covert this to read from and write to csv? I can not get the $device to output to Export-csv. Throws error null!
Function NaaDeviceId {
Param ([string]$filename)
$LUNs = Import-CSV $filename
foreach ($Disk in $LUNs) {
$naa = $Disk.Naa
if ($naa.length -ne 36) { “NAA value must be 36 characters”; break }
$deviceString = $naa.ToCharArray()
$device = [char][Convert]::ToInt32(“$($deviceString[26])$($deviceString[27])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[28])$($deviceString[29])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[30])$($deviceString[31])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[32])$($deviceString[33])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[34])$($deviceString[35])”, 16)
$device
}
$|Export-Csv “C:\temp\NaaDeviceID.csv” -NoTypeInformation
}
NaaDeviceId “C:\temp\Protection Group_Builds\naasafe.csv”
Sam – yes, this can be done. Here are two examples that use the function in the original post.
First, one to do exactly what you asked:
And second, one to get the information from PowerCLI and export it to CSV — note this assumes that each VMFS volume contains only one Extent
First, one
Error
Convert-NaaIdToVmaxDeviceId : The term ‘Convert-NaaIdToVmaxDeviceId’ is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\Save-WK\Scripts\NaaConvert2.ps1:11 char:69
+ Add-Member -MemberType NoteProperty -Name “VmaxDeviceId” -Value $(Convert-NaaI …
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Convert-NaaIdToVmaxDeviceId:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Very useful post! I have a snippit to identify devices from a given Frame S/N here:
http://powerwtf.com/find-and-rename-san-devices-from-a-single-frame/
But I will definitely be expanding it with this code example; being able to know the exact device ID is imperative to being able to work with any storage type.
Thanks!
J
Thanks for this tip,
Does this work for Powershell v3.0? If it does I was wondering how do I convert DeviceID from SQLserver into a decimal value when printed? E.g. $DeviceID = $disk.DeviceID $deviceSpaceVal = $DeviceID.toDecimal. I have tried but it doesn’t work.
Help please,
Shuaib
Hi,
Can I have your contact number please