Hi Guys,
I would like to know if is there a way to get the HBA devices list from a given vmHBA with PowerCli.
Sure, try this.
Get-VMHost | %{ $esxImpl = $_ $esx = Get-View $esxImpl $esxImpl | Get-VMHostHba | %{ $hba = $_ Get-ScsiLun -Hba $hba | %{ $lun = $_ $row = "" | Select Host,HBA,Device $row.Host = $esxImpl.Name $row.HBA = $hba.Name $row.Device = ($esx.Config.StorageDevice.ScsiLun | where{$_.Key -eq $lun.Key} ).DisplayName $row } } }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try this.
Note it requires PowerCLI 4.1 !
Get-VMHost | %{ $esx = $_ $esx | Get-VMHostHba | %{ $hba = $_ Get-ScsiLun -Hba $hba | %{ $row = "" | Select Host,HBA,Device $row.Host = $esx.Name $row.HBA = $hba.Name $row.Device = $_.Extensiondata.DisplayName $row } } }
If you need a pre-PowerCLI 4.1 version let me know
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you Luc,
Can you make me a pre-Powercli 4.1 version?
Sure, try this.
Get-VMHost | %{ $esxImpl = $_ $esx = Get-View $esxImpl $esxImpl | Get-VMHostHba | %{ $hba = $_ Get-ScsiLun -Hba $hba | %{ $lun = $_ $row = "" | Select Host,HBA,Device $row.Host = $esxImpl.Name $row.HBA = $hba.Name $row.Device = ($esx.Config.StorageDevice.ScsiLun | where{$_.Key -eq $lun.Key} ).DisplayName $row } } }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD.
It throws an error from:
Get-ScsiLun -Hba $hba
Value cannot be found for the mandatory parameter VmHost
At :line:7 char:13
+ Get-ScsiLun <<<< $hba | %{
I don't see -hba as a valid entry following get-scsilun .
Are you running PowerCLI 4.1 ?
Get-PowerCLIVersion
The Get-ScsiLun cmdlet in that version has a -Hba parameter.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I do now and it works. Thanks.
LucD,
This code is exactly what I needed recently, however it only produces the actual displayname when querying vSphere(i) 4.x hosts.........When I query classic ESX 3.5, the displayname is always null........what would be the equivalent object/property combination to query from ESX 3.5?
LucD
Can we export the output in CSV format ? pls add the line for exporting in csv.
Thanks
Kumar
For ESX 3.5 the device name is in the CanonicalName property. I modified Luc's script to check for the ESX version and return the value of the CanonicalName property if the version is less than 4. I also added the export to a csv file requested by Kumar.
Get-VMHost | ForEach-Object { $esxImpl = $_ $esx = Get-View $esxImpl $esxImpl | Get-VMHostHba | ForEach-Object { $hba = $_ Get-ScsiLun -Hba $hba | ForEach-Object { $lun = $_ $scsilun = $esx.Config.StorageDevice.ScsiLun | Where-Object {$_.Key -eq $lun.Key} $row = "" | Select-Object -Property Host,HBA,Device $row.Host = $esxImpl.Name $row.HBA = $hba.Name if ($esxImpl.Version.Split(".")[0] -ge 4) { $row.Device = $scsilun.DisplayName } else { $row.Device = $scsilun.CanonicalName } $row } } } | Export-Csv -Path HbaDevices.csv -NoTypeInformation -UseCulture
Regards, Robert
that worked Robert!
thanks to you and LucD for your assistance!
Would it be possible to list the pathing type (round robin, MRU, fixed)? The script looks excellent but I just need to add that one column in.
Thanks!
Hi bmmikee01,
Welcome to the VMware Communities.
This new version of the script adds the MultipathPolicy property of the ScsiLun object to the output:
Get-VMHost | ForEach-Object { $esxImpl = $_ $esx = Get-View $esxImpl $esxImpl | Get-VMHostHba | ForEach-Object { $hba = $_ Get-ScsiLun -Hba $hba | ForEach-Object { $lun = $_ $scsilun = $esx.Config.StorageDevice.ScsiLun | Where-Object {$_.Key -eq $lun.Key} $row = "" | Select-Object -Property Host,HBA,Device,MultipathPolicy $row.Host = $esxImpl.Name $row.HBA = $hba.Name if ($esxImpl.Version.Split(".")[0] -ge 4) { $row.Device = $scsilun.DisplayName } else { $row.Device = $scsilun.CanonicalName } $row.MultipathPolicy = $_.MultipathPolicy $row } } } | Export-Csv -Path HbaDevices.csv -NoTypeInformation -UseCulture
Regards, Robert
Thank you very much for this, I really appreciate it. I do have one question though, when I run I get this:
Export-Csv : A parameter cannot be found that matches parameter name 'UseCulture'. At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Mike\pathing-report.ps1:22 char: 66
+ } | Export-Csv -Path HbaDevices.csv -NoTypeInformation -UseCulture <<<<
I was just going to remove the -UseCulture but I wasn't sure what its purpose was?
Thank you again.
It looks like you are still running PowerShell version 1. If you run the PowerShell command "$Host.Version.Major" it should return 2. That will mean that you are running PowerShell v2. If it returns 1 you should upgrade to PowerShell version 2.
The Export-CSV -UseCulture parameter tells PowerShell to generate the list seperator in the local culture. E.g. here in the Netherlands it is a semicolon instead of a comma. That makes it easier to open the output in Excel. Otherwise all the output will be in one Excel column.
That did it, it seems to be running great now. Thanks again!
Hi LucD
This works for me.. but here i need for cluster not for the single host so what changes i should do for the below script and also can we get lun name also..
Get-VMHost | %{
$esxImpl = $_
$esx = Get-View $esxImpl
$esxImpl | Get-VMHostHba | %{
$hba = $_
Get-ScsiLun -Hba $hba | %{
$lun = $_
$row = "" | Select Host,HBA,Device
$row.Host = $esxImpl.Name
$row.HBA = $hba.Name
$row.Device = ($esx.Config.StorageDevice.ScsiLun | where{$_.Key -eq $lun.Key} ).DisplayName
$row
}
}
}
Hi LucD,
Sorry to bump an old thread but I really like this script but I was wondering how I could also get the LUN ID and the Capacity information as well.
Is there a way to get this to work with powerpath devices? I can run the script fine on clusters that don't have powerpath, but when trying to run it against any cluster that has powerpath and I get this error over and over:
Get-ScsiLun : 2/25/2018 12:02:30 PM Get-ScsiLun Value cannot be null.
Parameter name: array
At D:\scripts\frank\storage\test4.ps1:6 char:11
+ Get-ScsiLun -Hba $hba | %{
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ScsiLun], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun
Thanks,
Hi LUCD,
Thanks for the script, if possible can you help to guide how to include LUN path state and number of target/devices in the same script. as this need to get the storage path report all the hosts in the vCenter.
Regards
Narayanan.