VMware Cloud Community
vsphereadminmcm
Contributor
Contributor

Export ESXi Storage Device paths in excel

Does anyone have a script that will export all ESXi storage WWN, devices, number of paths and path state?

I want to use it for an upcoming code upgrade on our storage array.

0 Kudos
7 Replies
LucD
Leadership
Leadership

Have you searched in this community?

What do you already have?


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

0 Kudos
vsphereadminmcm
Contributor
Contributor

Hi Luc, This is the code I started grooming for my environment. I got all the errors out but the script runs for a long time, I let it run for hours with no response output. 

I also looked at https://www.lucd.info/2011/11/14/storage-views-datastores/ but I was unsure how to get it to pull from the entire vSphere as there are multiple datacenters in each.

What I am looking for is the script to cycle through all ESXi hosts in vSphere, and report back the HBA device paths with status for an upcoming code upgrade on the storage array.

connnect-VIServer -Server 'myvc'

$exportDSPathCount=@()

#Get list of ESXi Hosts
$esxihosts=Get-Content C:\host list.txt
$countofESXi=$esxihosts.Count
For($i = 1$i -le $esxihosts.count$i++)
{
ForEach ($esxihost in $esxihosts) {
 $esxi = Get-VMHost -Name $esxihost
 $hbas = $esxi | Get-VMHostHba
ForEach ($hba in $hbas) {
 $scsiluns = $hba | Get-ScsiLun
ForEach ($scsilun in $scsiluns) { 
 $exportDSPaths=New-Object PSObject
 $scsipaths =$scsilun | Get-Scsilunpath |Select-Object *
 $LunPathPolicy=$scsilun.MultipathPolicy
 $PathCount=$scsipaths.Count
 $LunNaaID=$scsilun.CanonicalName
 $DS=Get-Datastore |Get-View |Where-Object {$_.Info.vmfs.Extent.DiskName -eq $LunNaaID}

#Write-Host $DS.Name,$LunNaaID,$LunPathPolicy,$PathCount,$hba.Name,$esxi.Name
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "EsxiHost" -Value $esxi.Name
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "DatastoreName" -Value $DS.Name
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "LunNAAID" -Value $LunNaaID
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "MultipathPolicy" -Value $LunPathPolicy
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "LunPathCount" -Value $PathCount
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "VmHBA Connected" -Value $hba.Name
 $datastore=$DS.Name
 $exportDSPathCount+=$exportDSPaths
 #Write-Progress -Activity “Scanning $datastore in $hba on $esxi” -status “Found $countofESXi esxi hosts and working on $esxi” -PercentComplete ($i / $esxihosts.count*100)
 }
 }
}
$exportDSPathCountExport-Csv -NoTypeInformation 'NJESXPATHS.csv'
}
0 Kudos
LucD
Leadership
Leadership

Check if this is faster

 

Connect-VIServer -Server 'myvc'

Get-Content -Path 'C:\host list.txt' -PipelineVariable line |
ForEach-Object -Process {
    $esx = Get-VMHost -Name $line
    $stor = Get-View -Id $esx.ExtensionData.ConfigManager.StorageSystem
    $stor.StorageDeviceInfo.ScsiLun | where{$_.DeviceType -eq 'disk'} |
    ForEach-Object -Process {
        $lun = $_
        $paths = $stor.StorageDeviceInfo.MultipathInfo.Lun | where{$_.Lun -eq $lun.Key}
        if($lun.CanonicalName -eq 'naa.6000c299d9d27e16d33d744a4f2446b8'){
            $LUN.CanonicalName
        }
        $ds = $stor.FileSystemVolumeInfo.MountInfo | where{$_.Volume.Extent.DiskName -contains $lun.CanonicalName}
        New-Object -TypeName PSObject -Property ([ordered]@{
            VMHost = $esx.Name
            HBA = $stor.StorageDeviceInfo.MultipathInfo.lun.Policy.Prefer.Split(':')[0] -join '|'
            CanonicalName = $lun.CanonicalName
            MultiPathPolicy = $paths.Policy.Policy -join '|'
            LUNPathCount = $paths.Count
            Datastore = $ds.Volume.Name
            DSType = $ds.Volume.Type
        })        
    }
} | Export-Csv -Path 'NJESXPATHS.csv' -NoTypeInformation -UseCulture

 

 


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

0 Kudos
vsphereadminmcm
Contributor
Contributor

Thanks Luc, Here is the error that comes up.

 

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\bgonzales-a\Documents\scripts\DSPathInfo-v2.ps1:15 char:9
+ New-Object -TypeName PSObject -Property ([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\bgonzales-a\Documents\scripts\DSPathInfo-v2.ps1:15 char:9
+ New-Object -TypeName PSObject -Property ([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\bgonzales-a\Documents\scripts\DSPathInfo-v2.ps1:15 char:9
+ New-Object -TypeName PSObject -Property ([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

0 Kudos
LucD
Leadership
Leadership

I had a type in the HBA property.

I corrected the code above.
But I'm not sure why you would have a $null entry in there.


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

0 Kudos
vsphereadminmcm
Contributor
Contributor

HI Luc, not sure I follow.. Can you paste the code please?

0 Kudos
LucD
Leadership
Leadership

I corrected the code I posted earlier inline.
Just do a new copy/paste


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

0 Kudos