Script to Get the Path Count of VMHBA

Hello guys…

Here is the script  to get the Number of Paths for each and every VMHBA in esxi and the out put will be saved in CSV Files…Thanks to Lucd…

Script:

Connect-VIServer -Server vcenterservername -User vcenterusername -password vcenterpassword
$exportData=@()
$esxs=gc C:\Users\TIRU\hosts.txt
foreach($esxi in $esxs){
$esx = Get-VMHost -Name $esxi
foreach($hba in (Get-VMHostHba -VMHost $esx ))
{
$target = ($hba.VMhost.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target
$luns = Get-ScsiLun -Hba $hba 
$nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum
$exportObject=New-Object PSObject 
$exportObject |Add-Member -MemberType NoteProperty -Name "HostName" -Value $esx
$exportObject |Add-Member -MemberType NoteProperty -Name "HBAName" -Value $hba.Device
$exportObject |Add-Member -MemberType NoteProperty -Name "NumberOfPaths" -Value $nrPaths
#NumberOfPaths=$nrPaths
#HostName=$esx
#HBAName=$hba.Device
#NumberOfTargets=$target.Count
#NumberOfDevices=$luns.Count
$exportData+=$exportObject
}
}
$exportData| Export-Csv -NoTypeInformation 'ESXiStoragePathInformation.csv' 

Sample Output:

SampleOutput Of Script

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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