PowerCLI – Get-LunPathState

When the storage team needs to make changes to core switches in the SAN, being able to check the state of hundreds of paths quickly during fail-over is simply not viable with the GUI.

A couple of notes before you run
I am excluding my local disks which all start with naa.644a84* or naa.6141877* using a filter; {$_.CanonicalName -notlike “naa.644a84*” -and $_.CanonicalName -notlike “naa.6141877*”}
Clusters are hard-coded into script, adjust as required, look for the variable $AllHosts, alternatively you can run on all clusters
My output path is C:\vSpherePowerCLI\Output\ if you have a default install in PowerCLI then adjust acordingly

 

[code language=”powershell”]

# Get-LunPathState
# russ nov 2015
# Script reports the lists the Path and Path State for every vSphere Datastore and then output to CSV
# acknowledgement Eric Sarakaitis
# acknowledgement http://www.vmwareadmins.com/list-the-path-and-path-state-for-every-vsphere-datastore-using-powercli/

Write-Host "——————————————————- " -ForegroundColor DarkYellow
Write-Host "Clusters are hard-coded into script, adjust as required " -ForegroundColor Yellow
Write-Host "csv saved to C:\vSpherePowerCLI\Output\… " -ForegroundColor White
Write-Host "——————————————————- " -ForegroundColor DarkYellow

$initalTime = Get-Date
# Output path – this is my standard path, you should adjust according to your
$filepath = "C:\vSpherePowerCLI\Output\"
$filename = "LunPathState"
$date = Get-Date ($initalTime) -uformat %Y%m%d
$time = Get-Date ($initalTime) -uformat %H%M

Write-Host "$(Get-Date ($initalTime) -uformat %H:%M:%S) – Starting"

# $AllHosts = Get-VMHost | Sort Name
# Select only hosts from these clusters
$AllHosts = Get-Cluster cluster1, cluster2 | Get-VMHost | Sort Name

$reportLunPathState = @()

Write-Host "$(Get-Date -uformat %H:%M:%S) – $($AllHosts.length) hosts acquired"

$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 – this captures local disk, the next like filters local disks -notlike “*ATA*
#The following line filters local my disks which all start with naa.644a84* or naa.6141877*
$VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk | ? {$_.CanonicalName -notlike "naa.644a84*" -and $_.CanonicalName -notlike "naa.6141877*"}
ForEach ($VMHostScsiLun in $VMHostScsiLuns) {
$VMHostScsiLunPaths = $VMHostScsiLun | Get-ScsiLunPath
$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
}
}

$conclusionTime = Get-Date
Write-Host "$(Get-Date ($conclusionTime) -uformat %H:%M:%S) – Finished"
$totalTime = New-TimeSpan $initalTime $conclusionTime
Write-Host "$($totalTime.Hours):$($totalTime.Minutes):$($totalTime.Seconds) – Total Time"

$reportLunPathState | Out-GridView

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

[/code]

This will output to grid view as well as leaving a csv with date and time

tags: san, vsphere, luns, storage paths, failovers

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.