For PowerCLI builds before 4.1 it only needs a small adaption.
$esx = Get-VMHost <hostname> foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){ $target = ((Get-View $hba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target $luns = Get-ScsiLun -Hba $hba -LunType "disk" $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try this
$esx = Get-VMHost <hostname> foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){ $target = ($hba.VMhost.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target $luns = Get-ScsiLun -Hba $hba -LunType "disk" $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The next script will give you the number of targets, devices and paths of all the HBA's of all your hosts:
Get-VMHost | Sort-Object -property Name | ForEach-Object { $VMHost = $_ $VMHost | Get-VMHostHba | Sort-Object -property Device | ForEach-Object { $VMHostHba = $_ $ScsiLun = $VMHostHba | Get-ScsiLun If ($ScsiLun) { $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | ` Where-Object {$_.Name -like "$($VMHostHba.Device)*"} $Targets = ($ScsiLunPath | ` Group-Object -Property SanID | Measure-Object).Count $Devices = ($ScsiLun | Measure-Object).Count $Paths = ($ScsiLunPath | Measure-Object).Count } Else { $Targets = 0 $Devices = 0 $Paths = 0 } $Report = "" | Select-Object -Property VMHost,HBA,Targets,Devices,Paths $Report.VMHost = $VMHost.Name $Report.HBA = $VMHostHba.Device $Report.Targets = $Targets $Report.Devices = $Devices $Report.Paths = $Paths $Report } }
Regards, Robert
Thanks LucD for the quick update, and it worked. You will have to use PowerCLI 4.1. Didn't work in 4.0
Thank you Robert.
The Target and Paths were blank. The Devices reported correctly. Thanks again for the reply.
For PowerCLI builds before 4.1 it only needs a small adaption.
$esx = Get-VMHost <hostname> foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){ $target = ((Get-View $hba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target $luns = Get-ScsiLun -Hba $hba -LunType "disk" $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My scripts works good in my environment with PowerCLI 4.1. Maybe it doesn't work with PowerCLI 4.0 or earlier. In that case you better use Luc's script.
Robert, I think the problem is with this line (I get it as well with PowerCLI 4.1).
$ScsiLunPath = $ScsiLun | Get-ScsiLunPath | ` Where-Object {$_.Name -like "$($VMHostHba.Device)*"}
The name of the path doesn't always start with the HBA name.
If you do
$ScsiLunPath = $ScsiLun | Get-ScsiLunPath | ` Where-Object {$_.Name -like "*$($VMHostHba.Device)*"}
or
$ScsiLunPath = $ScsiLun | Get-ScsiLunPath | ` Where-Object {$_.Name.Contains($VMHostHba.Device)}
your script will work, except for iScsi LUNs where the path doesn't contain the HBA name at all.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You guys rocks. Love the community.
Happy Holidays!
The script worked great! Thank you very much for this!!!
I'm new to powershell and could use a bit of help making a small modification. I'd like to target just a cluster instead of the entire infrastructure. I am trying to get something like this working:
foreach ($VMHost in get-cluster
Would anyone happen to have some ideas how to do it?
Thanks!
Hi Todd,
you can do the following to select only the hosts in one cluster:
Get-Cluster <CLUSTERNAME> | Get-VMHost | Sort-Object -property Name | ForEach-Object) { $VMHost = $_ ... }
Regards, Robert
Okay that worked! However I just noticed that the original and new script does not display the Targets and Paths for an ESXi 4.0 host. It works great on a 3.5 host. I'm using PowerCLI 4.1. Any ideas?
Thanks!
hi LucD & Rob
any updates if i run it on ESXi 5??
Do you get any errors when you run it in a vSphere 5 environment ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes:
Get-ScsiLun : 15/07/2013 09:01:01 Get-ScsiLun Value cannot be null.
Parameter name: array
At line:5 char:14
+ $luns = Get-ScsiLun -Hba $hba -LunType "disk"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ScsiLun], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun
Get-ScsiLun : 15/07/2013 09:01:01 Get-ScsiLun ScsiLun with luntype 'disk' was not found using the specified filter
(s).
At line:5 char:14
+ $luns = Get-ScsiLun -Hba $hba -LunType "disk"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-ScsiLun], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScs
iLun
i guess its somthing about the EMC PowerPath
please advice?
small update
Robert script work fine on vSphere 5 environment but didnt get Targets and Paths number
only devices
There used to be indeed a problem with the Get-ScsiLun cmdlet when PowerPath was installed.
Which PowerCLI version are you using ? Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.1 Release 2 build 1012425
---------------
Snapin Versions
---------------
VMWare AutoDeploy PowerCLI Component 5.1 build 768137
VMWare ImageBuilder PowerCLI Component 5.1 build 768137
VMware vCloud Director PowerCLI Component 5.1 build 1012427
VMware License PowerCLI Component 5.1 build 669840
VMware VDS PowerCLI Component 5.1 build 1012428
VMware vSphere PowerCLI Component 5.1 build 1012428
That's the latest version.
So it seems that the PowerPath "feature" might still be there I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
there is any way to pass it?