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:


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
}

The function expects just one parameter and can be used like this:

Convert-NaaIdToVmaxDeviceId "naa.60000970000000000000533031363641"

9 comments

  1. 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!

  2. 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”

  3. 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:

    Import-Csv C:\tmp\naaSafe.csv | %{ 
      Add-Member -MemberType NoteProperty -Name "VmaxDeviceId" -Value $(Convert-NaaIdToVmaxDeviceId ($_.NaaId)) -passthru -InputObject $_ 
    } | Export-Csv c:\tmp\naaSafeOut.csv -NoTypeInformation
    

    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

    Get-Datastore | ?{$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess} | 
    Select-Object Name, FreeSpaceMB, CapacityMB,
    @{N="VmaxDeviceId";E={ (Convert-NaaIDToVmaxDeviceId $_.ExtensionData.info.vmfs.Extent[0].DiskName) }} |
    Export-Csv "C:\tmp\myNaaIds.csv" -NoTypeInformation
    
  4. 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

  5. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2026 Enterprise Admins.org. Design inspired by the Clarity Design System. Not affiliated with or endorsed by Broadcom or VMware.