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

esx-lun

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
        }
    }
    else
        {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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: