In this post we are sharing a PowerCLI script that we used to export a list of LUNs attached to ESXi hosts in a cluster along with the details of Path Selection Policy selected for the LUN and CommandsToSwitchPath parameter set for the LUNs.
Script was tested on below versions:
- PowerCLI version 11.5.0 build 14912921
- vSphere 6.7U3
Script:
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred
$getCluster = Get-Cluster -Name "Cluster_Name"
$getESXis = $getCluster | Get-VMHost
$printluns=@()
foreach ($getESXi in $getESXis)
{
$getLUNsforESXi = Get-VMhost $getESXi | Get-ScsiLun -LunType disk | Select VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath
$printluns = $printluns + $getLUNsforESXi
}
$printluns | Export-Csv C:\users\Administrator\Desktop\PathtoSaveFile.csv -NoTypeInformation
Disconnect-VIServer -Confirm:$false
Just replace the vCenter_Server_IP_Address/FQDN, Cluster_Name and Path of CSV File and run the script to generate a report of LUNs mapped to all ESXi hosts in a vSphere cluster in your environment. BOOM!!
Happy Scripting!!
