PowerCLI To Get LUN ID Number & Info

Thought I would share another script that came in handy recently. While troubleshooting an issue where a data store needed to be expanded we found that the storage would never show up on the vSphere side. On the storage side, all looked correct and was showing correctly. After looking at each host I noticed that the LUN id on each host for the storage presented was different.  After digging around in the storage controller I found that the LUN id was set to auto. After hours that day, I went in and manually set the LUN ids and refreshed the storage system in each ESXi host. This corrected the issue and I was able to expand the data store in question. After the work was complete I did some research and came up with a script that would list all the LUNs for each ESXi host and show the ID along with other useful information. The next time I run into this issue the troubleshooting time will drastically be reduced. Below is the script, I hope it will be as useful to you. Also adding a github link.


Write-Host "Gather LUN info" -ForegroundColor Yellow

# Get VMFS volumes. Ignore local SCSILuns.

Get-VMHost | Get-ScsiLun | Sort-Object VMhost | Select-Object VMHost, CanonicalName, CapacityGB, Vendor, MultipathPolicy, LunType, IsLocal, IsSsd,@{n='LunID';E={


      $esxcli = Get-EsxCli -VMHost $_.VMHost-V2



Sort-Object -Property {[int]$_.LUN}| Export-Csv C:\temp\Luns.csv -NoTypeInformation