Script to check for single paths and dead paths

Here we are, script amended to report only on single paths and dead paths for scsi luns

$initalTime = Get-Date
$filepath = "C:tmp"
$filename = "LunPathState"
$date = Get-Date ($initalTime) -uformat %Y%m%d
$time = Get-Date ($initalTime) -uformat %H%M

$AllHosts = Get-VMHost | Sort Name

$reportLunPathState = @()

$i = 0

ForEach ($VMHost in $AllHosts) {
$i++
Write-Host "$(Get-Date -uformat %H:%M:%S) - $($i) of $($AllHosts.length) - $($VMHost)"
$VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk
ForEach ($VMHostScsiLun in $VMHostScsiLuns) {
$VMHostScsiLunPaths = $VMHostScsiLun | Get-ScsiLunPath
If ((($VMHostScsiLunPaths | Measure-Object).Count -eq 1 )) {
$reportLunPathState += ($VMHostScsiLunPaths | Measure-Object) | Select @{N="Hostname"; E={$VMHost.Name}}, @{N="Number of Paths"; E={$_.Count}}, Name, State
$reportLunPathState += $VMHostScsiLunPaths | Select @{N="Hostname"; E={$VMHost.Name}}, "Number of Paths", Name, State
}
ForEach ($VMHostScsiLunPath in $VMHostScsiLunPaths) {
If ($VMHostScsiLunPath.State -eq "Dead") {
$reportLunPathState += ($VMHostScsiLunPath | Measure-Object) | Select @{N="Hostname"; E={$VMHost.Name}}, @{N="Number of Paths"; E={$_.Count}}, Name, State
$reportLunPathState += $VMHostScsiLunPath | Select @{N="Hostname"; E={$VMHost.Name}}, "Number of Paths", Name, State
}}
}
if ($i -eq 2) {break}
}

$reportLunPathState | Out-GridView
$reportLunPathState | Export-Csv $filepath$date$time"-"$filename".csv" -NoType

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