Sunday, June 22, 2014

One-liner to list names, NAA ids of the boot luns in a cluster

One-liner to list hosts, datastore names, and NAAs of the boot luns in a cluster.
get-cluster "cluster01" | get-vmhost | sort-object name | get-datastore | where-object {$_.CapacityGB -lt 100} | select @{n="host";e={($_ | get-vmhost | select name).name}}, name, @{n="NAA";e={($_ | get-scsilun | select canonicalname).canonicalname}}


Broken down:
  1. Get-cluster "cluster01" - start by getting the cluster
  2. get-vmhost - get all the ESXi hosts in the cluster
  3. sort-object name - optional to sort the hosts by name
  4. get-datastore - get the datastores attached to the hosts
  5. where-object {$_.CapacityGB -lt 10} - filters only the small datastores*.
  6. Select-object - pick the properties to display
  7. @{n="host";e={($_ | get-vmhost | select name).name}} - shows the name of the vmhost
  8. name - shows the name of the datastore object
  9. @{n="NAA";e={($_ | get-scsilun | select canonicalname).canonicalname}} - shows the naa of the datastore
*Adjust this where clause depending on how you can identify the boot luns in your environment. For example, if you name all your boot luns with 'boot' in them, you could use where-object {$_.name -like "*boot*"}. I pick all the small datastores because if the datastore is less than 10GB in our environment, it's always a boot lun.

Not all the fields may display completely on your screen. You can always pipe to out-file to dump the info to a text file or pipe to format-list

Sample output:
host     Name          NAA
----     ----          ---
hostab01 hostab01-boot naa.6005076801818...
hostab02 hostab02-boot naa.6005076801818...
hostab03 hostab03-boot naa.6005076801808...
hostab04 hostab04-boot naa.6005076801808...
hostab05 hostab05-boot naa.6005076801808...

No comments:

Post a Comment