I am trying to get a script working to show path status for multiple hosts, with the hope to show dead paths, and export the results to CSV. I found this post, and have been attempting to build o...
See more...
I am trying to get a script working to show path status for multiple hosts, with the hope to show dead paths, and export the results to CSV. I found this post, and have been attempting to build on it. When I run the script against multiple hosts, the CSV does not show the hostnames in the output. Also, will this script output dead paths?
& {
$esx = Get-VMHost -Name (Get-Content "C:\Scripts\esxhosts.txt")
foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){
$target = $hba.VMhost.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter |
where {$_.Adapter -eq $hba.Key} | %{$_.Target}
$luns = Get-ScsiLun -Hba $hba -LunType "disk" -ErrorAction SilentlyCOntinue | Measure-Object | Select -ExpandProperty Count
$nrPaths = $target | %{$_.Lun.Count} | Measure-Object -Sum | select -ExpandProperty Sum
$hba | Select @{N="VMHost";E={$_.Entity.Name}},@{N="HBA";E={$hba.Name}},
@{N="Target#";E={if($target -eq $null){0}else{@($target).Count}}},@{N="Device#";E={$luns}},@{N="Path#";E={$nrPaths}}
}
} | Export-Csv "C:\Scripts\pathstatus.csv" -NoTypeInformation -UseCulture