What is one-liner
? This is just one line of code (PowerShell/VMware PowerCLi or whatever) intended to perform particular task. It may be very or sometimes very-very long, but is still one line only!
This one-liner retrieves pathing
info for ESXi hosts. In the vSphere Client this info exists here: Select a host -> Configure
tab -> category Storage
-> child category Storage Devices
-> select your device in Storage Devices
list -> move to Paths
tab.
Five clicks for every device! What if you have small six hosts cluster with five Datastores mounted in every host? Simple math gives me 150 clicks! Let’s do that in one-line w/PowerCLi.
1Liner
Get-ScsiLun -VmHost (Get-VMHost | sort Name) -LunType disk,storageArrayController | select VMHost, @{N='NAA';E={$_.CanonicalName}}, @{N='LUN';E={([regex]::Match($_.RuntimeName, ':L(\d+)$').Groups[1].Value) -as [int]}}, @{N='CapacityGiB';E={[math]::Round($_.CapacityGB)}}, @{N='Paths'; E={($_ | Get-ScsiLunPath | ? {$_.State -eq 'Active'} | select ScsiLun | sort ScsiLun | group ScsiLun | select Count).Count}} | sort Paths, LUN | Export-Csv -notype .\MultiPathingReport.csv
Customizations
- Get report for particular HA/DRS cluster (add
Get-Cluster
to-VmHost
parameter ofGet-ScsiLun
cmdlet).
Get-ScsiLun -VmHost (Get-Cluster PROD | Get-VMHost | sort Name) -LunType disk,storageArrayController | select VMHost, @{N='NAA';E={$_.CanonicalName}}, @{N='LUN';E={([regex]::Match($_.RuntimeName, ':L(\d+)$').Groups[1].Value) -as [int]}}, @{N='CapacityGiB';E={[math]::Round($_.CapacityGB)}}, @{N='Paths'; E={($_ | Get-ScsiLunPath | ? {$_.State -eq 'Active'} | select ScsiLun | sort ScsiLun | group ScsiLun | select Count).Count}} | sort Paths, LUN | Export-Csv -notype .\MultiPathingReport.csv
- Filter out LUN with no multi pathing (LUN that have less than two paths).
Get-ScsiLun -VmHost (Get-Cluster PROD | Get-VMHost | sort Name) -LunType disk,storageArrayController | select VMHost, @{N='NAA';E={$_.CanonicalName}}, @{N='LUN';E={([regex]::Match($_.RuntimeName, ':L(\d+)$').Groups[1].Value) -as [int]}}, @{N='CapacityGiB';E={[math]::Round($_.CapacityGB)}}, @{N='Paths'; E={($_ | Get-ScsiLunPath | ? {$_.State -eq 'Active'} | select ScsiLun | sort ScsiLun | group ScsiLun | select Count).Count}} | sort Paths, LUN | ? {$_.Paths -lt 2} | Export-Csv -notype .\MultiPathingReport.csv
- Get report for a single vSphere host.
Get-ScsiLun -VmHost (Get-VMHost esx1.domain.com) -LunType disk,storageArrayController | select VMHost,@{N='NAA';E={$_.CanonicalName}}, @{N='LUN';E={([regex]::Match($_.RuntimeName, ':L(\d+)$').Groups[1].Value) -as [int]}}, @{N='CapacityGiB';E={[math]::Round($_.CapacityGB)}}, @{N='Paths'; E={($_ | Get-ScsiLunPath | ? {$_.State -eq 'Active'} | select ScsiLun | sort ScsiLun | group ScsiLun | select Count).Count}} | sort Paths, LUN | ft -au
- Redirect the output to the Grid control (
| Out-GridView
).
Get-ScsiLun -VmHost (Get-VMHost | sort Name) -LunType disk,storageArrayController | select VMHost, @{N='NAA';E={$_.CanonicalName}}, @{N='LUN';E={([regex]::Match($_.RuntimeName, ':L(\d+)$').Groups[1].Value) -as [int]}}, @{N='CapacityGiB';E={[math]::Round($_.CapacityGB)}}, @{N='Paths'; E={($_ | Get-ScsiLunPath | ? {$_.State -eq 'Active'} | select ScsiLun | sort ScsiLun | group ScsiLun | select Count).Count}} | sort Paths, LUN | ogv
How to use
- Connect to your VCenter(s)/ESXi Host(s).
Connect-VIServer VC1, VC2 -wa SilentlyContinue
Copy-Paste
the code to the PowerShell console and hitEnter
. That’s all.
Used cmdlets
- The core cmdlets.
Get-ScsiLun Get-ScsiLunPath
- Auxiliary cmdlets
Get-Cluster Get-VMHost Where-Object Sort-Object Select-Object Group-Object Format-Table Export-Csv Out-GridView
More 1Liners
Eject CDROM drive for all VMware VM
Add PowerCLi version to the $PSVersionTable variable