function Get-LUNPathState { <# .SYNOPSIS No parameters needed. Just execute the script. .DESCRIPTION This script outputs the number of paths to each LUN. .EXAMPLE Get-LUNPathState -VMhosts 'esx01' Lists all LUN pats for ESXi host esx01. .EXAMPLE $esxihosts = Get-VMHost Get-LUNPathState -VMHosts $esxihosts Lists all LUN paths for all ESXi hosts in $esxihosts .NOTES Author: Patrick Terlisten, patrick@blazilla.de, Twitter @PTerlisten This script is provided "AS IS" with no warranty expressed or implied. Run at your own risk. This script is based on: http://www.vmwareadmins.com/list-the-path-and-path-state-for-every-vsphere-datastore-using-powercli/ This work is licensed under a Creative Commons Attribution NonCommercial ShareAlike 4.0 International License (https://creativecommons.org/licenses/by-nc-sa/4.0/). .LINK http://www.vcloudnine.de #> [CmdletBinding()] Param( [Parameter(Mandatory = $true, Position = 0, HelpMessage = 'ESXi Host', ValueFromPipeline = $true)] [Alias('Name')] [ValidateNotNullorEmpty()] $VMhosts ) # Create empty hash table $ReportLunPathState = @() # Initialize counter variable $i = 0 try { ForEach ($VMHost in $VMhosts) { # Increment counter variable $i++ # Get all datastores from the current host $VMHostDatastores = Get-Datastore # Get all disks devices from the current host $VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk ForEach ($VMHostScsiLun in $VMHostScsiLuns) { # Get LUN paths for each disk device $VMHostScsiLunPaths = $VMHostScsiLun | Get-ScsiLunPath # Count paths per disk device $ReportLunPathState += ($VMHostScsiLunPaths | Measure-Object) | Select-Object ` -Property @{N = 'Hostname'; E = { $VMHost.Name } }, ` @{N = 'Datastore'; E = { $VMHostDatastores | Where-Object -FilterScript { ($_.extensiondata.info.vmfs.extent | ForEach-Object -Process { $_.diskname }) -contains $VMHostScsiLun.CanonicalName } | Select-Object -ExpandProperty name } }, ` @{N = 'CanonicalName'; E = { $VMHostScsiLun.CanonicalName } }, ` @{N = 'Paths'; E = { $_.Count } }, ` @{N = 'Path State'; E = { $VMHostScsiLunPaths.State } }, ` @{N = 'IsLocal'; E = { $VMHostScsiLun.IsLocal } } } } } catch { "Error was $_" $line = $_.InvocationInfo.ScriptLineNumber "Error was in Line $line" } finally { $ReportLunPathState } } $output = @() foreach ($cluster in Get-Cluster) { $luns = @() #var to collect lun info from hosts foreach ($esxi in $cluster | get-vmhost) { foreach ($lun in ($esxi | Get-LUNPathState)) { $result = "" | Select Hostname, Datastore, Paths, PathState, IsLocal $result.Hostname = $lun.Hostname $result.Datastore = $lun.Datastore $result.Paths = $lun.Paths $result.PathState = $lun.PathState $result.IsLocal = $lun.IsLocal $luns += $result } } #check each ds and check if paths are consistent foreach($ds in ($luns | Group-Object -Property Datastore)){ $pathconsistency = $luns | Where-Object{$_.Datastore -eq $ds.Name} | Group-Object -Property Paths | Measure-Object #path consistents check $pathinfo = $luns | Where-Object{$_.Datastore -eq $ds.Name} | Group-Object -Property Paths if($pathconsistency.Count -gt 1 ){ foreach($esxi in $pathinfo.group){ $result = "" | Select Cluster, Hostname, Datastore, Paths $result.Cluster = (Get-VMhost -Name $esxi.Hostname).Parent $result.Hostname = $esxi.Hostname $result.Datastore = $esxi.Datastore $result.Paths = $esxi.Paths $output += $result } } } } $output $Title = "90 Cluster same LUN same Path-Count" $Header = "90 Cluster same LUN same Path-Count" $Comments = "LUNs have no consistent Path Count" $Display = "Table" $Author = "evoila GmbH" $PluginVersion = 1.0 $PluginCategory = "vSphere"