Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Last active June 14, 2016 08:06
Show Gist options
  • Save vMarkusK/85c0bd39b246169da81f3c15186fa138 to your computer and use it in GitHub Desktop.
Save vMarkusK/85c0bd39b246169da81f3c15186fa138 to your computer and use it in GitHub Desktop.
Reports ESXi Path-Count from all Devices via PowerCLI GET-ESXCLI -V2
# Start Load VMware Snapin (if not already loaded)
if (!(Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
if (!(Add-PSSnapin -PassThru VMware.VimAutomation.Core)) {
# Error out if loading fails
Write-Error "ERROR: Cannot load the VMware Snapin. Is the PowerCLI installed?"
Exit
}
}
# End Load VMware Snapin (if not already loaded)
# Start Global Definitions
$VIServer = "your-vCenter"
# End Global Definitions
# Start vCenter Connection
Write-Host "Starting to Process vCenter Connection to " $VIServer " ..."-ForegroundColor Magenta
$OpenConnection = $global:DefaultVIServers | where { $_.Name -eq $VIServer }
if($OpenConnection.IsConnected) {
Write-Host "vCenter is Already Connected..." -ForegroundColor Yellow
$VIConnection = $OpenConnection
} else {
Write-Host "Connecting vCenter..."
$VIConnection = Connect-VIServer -Server $VIServer
}
if (-not $VIConnection.IsConnected) {
Write-Error "Error: vCenter Connection Failed"
Exit
}
# End vCenter Connection
# Start Get all Connected Hosts
$myHosts = Get-VMHost | where {$_.ConnectionState -eq "Connected" -and $_.PowerState -eq "PoweredOn"}
# End Get all Connected Hosts
$Report = @()
foreach ($myHost in $myHosts) {
$esxcli2 = Get-ESXCLI -VMHost $myHost -V2
$devices = $esxcli2.storage.core.path.list.invoke() | select Device -Unique
foreach ($device in $devices) {
$arguments = $esxcli2.storage.core.path.list.CreateArgs()
$arguments.device = $device.Device
$LUNs = $esxcli2.storage.core.path.list.Invoke($arguments)
$LUNReport = [PSCustomObject] @{
HostName = $myHost.Name
Device = $device.Device
LUNPaths = $LUNs.Length
LUNIDs = $LUNs.LUN | Select-Object -Unique
}
$Report += $LUNReport
}
}
$Report | where {$_.LUNPaths -gt $MaxLUNPaths -or ($_.LUNIDs | measure).count -gt 1 } | ft -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment