Using PowerCLi to run a ESXCli command to find storage info

So recently I had to use VMware Health Analyzer in order to run a health check on a clients’ virtual environment alongside a colleague who was running Navisphere Analyzer against the clients’ EMC storage array.

We notice a slight problem where we couldn’t match up the LUN IDs from the storage (ie Channel:Target:Lun – which VMware refers to as Runtime name) and the UUIDs that are used in VMware (ie naa.xxxxxxx).

The Health Analyzer outputs only datastore/LUN information referencing the appropriate UUID. The EMC nar file generated outputs only LUN information referencing the appropriate LUN ID (well that’s what my colleague says – if anyone knows how to generate data using the VMware UUID then please let me know!).

So we pretty much had no reference to match up VMware Health Analyzer LUN data to the EMC Navisphere Analyzer LUN data…….

So a quick google sent me looking here:

But that would only be useful if you are able to sit on site and look at the vSphere Client/Navisphere GUI, plus it would be quite a tedious process to go through all the LUNs.

Sooooo…. after a lot of trial and error, and googling PowerCLI commands, I ended up writing the following script (with a little help from Luke’s scripts at

param([string[]]$vmhosts = $null)
#By default, PowerShells execution policy is set to Restricted; that means that scripts will not run.
#RemoteSigned allows PowerShell to run any scripts you write, but only run scripts from the Internet if they have been signed by a trusted publisher.
Set-ExecutionPolicy RemoteSigned
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue #required if running from normal Windows PowerShell and not VMware Powershell

function usage()
Write-host "This script is used to pull Storage information for all hosts provided."
Write-host "You can specify -vmhosts as an array:"
write-host "Get-LUN.ps1 -vmhosts (`"host1`",`"host2`",`"host3`")"

if ($vmhosts -eq $null)
#Checks to see if vmhosts parameter has been supplied when script is run

if ($vmhosts -ne $null)
#Credentials required for ESX hosts - assuming credentials will be same for all ESX hosts
$vmhost_creds = $host.ui.PromptForCredential("ESX/ESXi Credentials Required", "Please enter credentials to log into the ESX/ESXi host.", "", "")
foreach ($vmhost in $vmhosts)
connect-viserver $vmhost -credential $vmhost_creds > $NULL 2>&1
$esxcli = Get-EsxCli -VMHost $vmhost
#Outputs the data into a text file located in C:\ and will name the file using the host name
$ | Out-File c:\$vmhost.txt
disconnect-viserver -confirm:$false

#garbage collection
$vmhost_creds = $null
$vmhosts = $null
$esxcli = $null


So basically cut and paste the code into notepad and save it as Get_LUN.ps1 and run from a PowerShell console…….

The output will list all Adapters, UUIDs, Runtime Names, Identifiers, etc for the host.


If you want to limit the data obtained, then you could always pipe the data through a select filter before piping it to the output file….. so a bit like: $ | Select Adapter,Device,RuntimeName,Transport | Out-File c:\$vmhost.txt


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 )

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