PowerCLI script to get NAA and Datastore name of all storage on ESX Server

Use the following script to get a list of Datastores, their respective capacities and their corresponding NAAs on an ESX Server:

$esxName = "esx01.vi.local"

Connect-VIServer vs01.vi.local

New-VIProperty -Name lunDatastoreName -ObjectType ScsiLun -Value {

    $ds = $lun.VMHost.ExtensionData.Datastore | %{Get-View $_} | `
        where {$_.Summary.Type -eq "VMFS" -and
            ($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName})}
} -Force | Out-Null

Get-VMHost -Name $esxName | Get-ScsiLun | Select CanonicalName, CapacityMB, lunDatastoreName

To export the results to a CSV file run same script adding the following to the end of the last line:

 | Export-csv C:\DatastoreInfo.csv

I can’t remember where I got this script from, whoever it was, I thank-you sincerely! The Get-ScsiLun command line reference can be found here.

Credit to Whowe who added his method in the comments below which worked perfectly. His script code is directly below, I have added some connection parameters to show you how I would use it to get datastore info:

$esxName = "esx01.vi.local"

Connect-VIServer vs01.vi.local

Get-VMHost -Name $esxName | Get-Datastore |

Where-Object {$_.ExtensionData.Info.GetType().Name -eq "VmfsDatastoreInfo"} |

ForEach-Object {

if ($_)


$Datastore = $_

$Datastore.ExtensionData.Info.Vmfs.Extent |

Select-Object -Property @{Name="Name";Expression={$Datastore.Name}},




The output from the script is below which shows NAA as well as Datastore info (but not capacity):

[vSphere PowerCLI] C:\Admin> .\GetDSInfo.ps1

Name                           Port  User
----                           ----  ----
vs01.vi.local                  443   DOMAIN\admin

Name     : datastore-1-R1
DiskName : naa.6848f690ec8be200191117982eb0b641

Name     : datastore-2-R5
DiskName : naa.60000970000295800173533030384646

Hope this benefits someone out there and thanks to Whowe for his contribution!

PowerCLI command to list all PortGroups on an ESX/ESXi host

A Lead Engineer asked me to send him a list of all PortGroups on a specific ESX host (running ESX 4.1). Due to the time and effort required to obtain this info manually, I had to use PowerCLI. I ran the command below:

Get-VirtualPortGroup -VMHost esx1 | select Name, VirtualSwitch, VLanId

It outputs results similar to the below:

Name                     VirtualSwitch      VLanId
----                     -------------      ------
DMZ-VLAN                 vSwitch0           1139
Inside-VLAN              vSwitch0           805
VMNet                    vSwitch1           0
VMNet-KS                 vSwitch1           124
VMNet-SC                 vSwitch1           0
VMNet-vmk                vSwitch1           0
Backup-Inside-VLAN       vSwitch2           648
Backup-DMZ-VLAN          vSwitch2           647

To get the results in a spreadsheet export the results to a csv file per the below:

Get-VirtualPortGroup -VMHost esx1 | select Name, VirtualSwitch, VLanId | | Export-Csv C:\VMHostNetworkInfo.csv

The full command line reference for Get-VirtualPortGroup is available here.