Matching the ESX and storage LUNs

It has been always a problem to match LUNs on ESX to LUNs on a storage. Eventually I wrote a short script to make this work way easier

The actual match can always be done via naa LUN number. It is not difficult for any storage (EMC, NetApp, etc.) to get the CSV file containing the storage LUNs with their naa numbers.  But then my usual way was to find an ESX LUN naa number in the GUI and match it against storage naa manually, like this


It works well if there are a few LUNs to match. It is really a time-consuming operation for many LUNs.

So, here’s the script for VMware PowerCLI. The most important parts are highlighted in bold red. $Extent.DiskName is an naa number.

$Datastores = Get-DataStore

Foreach ($Datastore in $Datastores)
    Write-Host $Datastore.Name
    $LineHeader = $Datastore.Name + “;” + $Datastore.CapacityGB + “;” + $Datastore.Type + “;”
    if ($Datastore.ExtensionData.Info.GetType().Name -match “VmfsDatastoreInfo”)
        $LineHeader = $LineHeader + $Datastore.ExtensionData.Info.VMFS.BlockSizeMb + “;”
        $Extents = $Datastore.ExtensionData.Info.VMFS.Extent
        Foreach ($Extent in $Extents)
            $Line = $LineHeader + $Extent.DiskName + “;” + $Extent.Partition
            Add-Content $OutputFileName -value $Line
        {Add-Content $OutputFileName -value $LineHeader}

The result is saved in the $OutputFileName with “;” as a delimiter. Open it in Excel and use VLookup to match against the storage LUNs.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: