Dead Paths list using powershell

Dead Paths are always been an headache for vmware admin. Some cases that leads host into not responding state. Here i am sharing powershell script to pull dead path list from vcenter. you can modify it accordingly if you want to run it for specific cluster/host.



Connect-VIServer vcsa65

#Get list of ESXi Hosts
# remove -location parameter if you want to run for complete vcenter
$vmhosts = @(Get-VMHost -Location Dev)
$i=0

$result = ForEach ($vmhost in $vmhosts) {
    $i++
    Write-Progress -Activity "Scanning hosts" -Status ("Host: {0}" -f $vmhost.Name) -PercentComplete ($i/$vmhosts.count*100) -Id 0
    $hbas = $vmhost | Get-VMHostHba
    $j=0
    ForEach ($hba in $hbas) {
        $j++
        Write-Progress -Activity "Scanning HBAs" -Status ("HBA: {0}" -f $hba.Device) -PercentComplete ($j/$hbas.count*100) -Id 1
        $luns = $hba | Get-ScsiLun
        $k=0
        ForEach ($lun in $luns) {
            $k++
            Write-Progress -Activity "Scanning Luns" -Status ("Lun: {0}" -f $lun.CanonicalName) -PercentComplete ($k/$luns.count*100) -Id 2
            $paths = $lun | Get-Scsilunpath
            $l=0
            ForEach ($path in $paths) {
                $l++
                Write-Progress -Activity "Scanning Paths" -Status ("Path: {0}" -f $path.Name) -PercentComplete ($l/$paths.count*100) -Id 3
                New-Object PSObject -Property @{
                    Host = $vmhost.name
                    HBAName = $lun.RuntimeName
                    PathSelectionPolicy = $lun.MultiPathPolicy
                    Status = $path.state
                    Source = "{0}" -f ((("{0:x}" -f $hba.PortWorldWideName) -split '([a-f0-9]{2})' | where {$_}) -Join ":")
                    Target = $path.SanId
                    LUN = (($lun.RunTimeName -Split "L")[1] -as [Int])
                    Path = $path.Name
                }
            }
        }
    }
}

$result| Export-Csv -NoTypeInformation 'F:\script_output\deadpathinfo.csv'

No comments:

Post a Comment