EdZ
Contributor
Contributor

Script to map out datastores to NAA ID's?

Jump to solution

Does anyone have a script to map a list of datastores from a host or cluster along with the the NAA ID's? I have found scripts that gather various types of information on the LUN's on hosts and clusters but don't associate a datastore to a LUN (or extents). The reason behind this is that I am trying to find a way to create a list of datastores and be able to identify their associated LUN's on the disk array. Perhaps a different method would work better? In the case of the NAA ID this includes the WWN of the disk as part of the structure (at least for EMC devices) so it can be used to identify the LUN in the array. Right now, the method I am using to identify the disks is to run two commands at the console:

esxcfg-scsidevs -m

Which identifies the datastore name and corresponding mount point in the console (for example /dev/sdz), and

INQ -sym_wwn (Linux utility)

to match up the mount point with the device ID. From what I understand this won't work in ESXi 4 or ESXi 5.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
lockenkeyster
Enthusiast
Enthusiast

Like this?:

$myDS = Get-Datastore
$results = @()
foreach ($ds in $myDS) {
$dsview = $ds | Get-View
$thisDS = "" | Select "DatastoreName","CanonicalName"
$thisDS."DatastoreName" = $ds.Name
$thisDS."CanonicalName" = $dsview.info.vmfs.extent
$results += $thisDS
}
$results

View solution in original post

0 Kudos
4 Replies
lockenkeyster
Enthusiast
Enthusiast

Like this?:

$myDS = Get-Datastore
$results = @()
foreach ($ds in $myDS) {
$dsview = $ds | Get-View
$thisDS = "" | Select "DatastoreName","CanonicalName"
$thisDS."DatastoreName" = $ds.Name
$thisDS."CanonicalName" = $dsview.info.vmfs.extent
$results += $thisDS
}
$results

0 Kudos
LucD
Leadership
Leadership

That script will show the information you are after.

A slightly different approach which shows all visible LUNs in a cluster, including RDM and free LUNs, can be found in my LUN report – datastore, RDM and node visibility post.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MaxMortillaro
Contributor
Contributor

Thank you for this nice script, it has been of great use today!

0 Kudos
vFantastic
Enthusiast
Enthusiast

I use the following oneliner...

Get-Cluster "ClusterName" | Get-VMHost | Get-Datastore | Where {$_.Name -notmatch "-Local" -and $_.Name -notmatch "NFS"} | Select Name,@{N="DiskName";E={$_.ExtensionData.Info.Vmfs.Extent.DiskName}}

It doesn't need the Where statement but I use it to exclude local and nfs datastores by leveraging good naming conventions.

Hope that helps...

0 Kudos