Hi All,
I'm trying to list the VMFS datastore & LUN path for a specific set of VMHost or ESXi servers, the below script was created by LucD, but I cannot get the column:
ESXiIP and the VMFS datastore label or name, PSP in the calculated property.
$report= @()
$esxilist = Get-VMHost -Name $esxName
foreach( $esxvm in $esxilist){
$esx = Get-VMHost -Name $esxvm
$esxcli = Get-EsxCli -VMHost $esxvm
$hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select- -ExpandProperty Name
$LUNs = Get-ScsiLun -VmHost $esx
$TheHost = $_
$_ | Get-Datastore | Where type -EQ VMFS | select
@{l="host";e={$TheHost.name}},
@{l="LUN";e={(Get-View $_).Info.Vmfs.Extent.diskname}},
@{l="Datastore Name";e={$_.name}},
@{l="PSP";e={($Luns | where CanonicalName -eq (Get-View $_).Info.Vmfs.Extent.diskname).multipathpolicy}}
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Device | %{
$row = "" | Select ESXiIP,ESXiName, VMFSDatastoreName1, VMFSDatastoreName2, Lun, NrPaths
$row.ESXiName = $Esxvm.NetworkInfo.HostName
$row.ESXiIP = $esxvm.NetworkInfo.ConsoleNic
$row.Lun = $_.Name
$row.VMFSDatastoreName1 = $esxcli.storage.FullName
$row.VMFSDatastoreName2 = $esxcli.storage.Name
$row.NrVM = (Get-View -Id $esx.ExtensionData.Vm -Property Name, Config.Template | where {-not $_.ExtensionData.Config.Template}).Count
$row.NrPaths = $_.Group.Count
$report += $row
}
}
$report | Out-GridView
Any help would be greatly appreciated.
Thank you in advance.
Try like this
Get-VMHost -Name $esxName -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx
$hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select -ExpandProperty Name
$LUNs = Get-ScsiLun -VmHost $esx
$net = Get-VMHostNetwork -VMHost $esx
$ds = Get-Datastore -VMHost $esx | where{$_.Type -eq 'VMFS'}
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Device -PipelineVariable group | ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
ESXiName = $net.HostName
ESXiIP = $net.VirtualNic.IP -join '|'
Lun = $group.Name
Datastore = ($ds | where{$_.ExtensionData.Info.Vmfs.Extent.DiskName -contains $group.Name}).Name
NrPaths = $_.Group.Count
PSP = ($luns | where{$_.CanonicalName -eq $group.Name}).MultipathPolicy
})
}
} | Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
$report= @()
$esxlist = Get-VMHost -Name $esxName
foreach( $esx in $esxlist){
$esxcli = Get-EsxCli -VMHost $esx
$hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select -ExpandProperty Name
$LUNs = Get-ScsiLun -VmHost $esx
$net = Get-VMHostNetwork -VMHost $esx
Get-Datastore -VMHost $esx | Where type -EQ VMFS | select @{l="host";e={$esx.name}},
@{l="LUN";e={$_.ExtensionData.Info.Vmfs.Extent.diskname}},
@{l="Datastore Name";e={$_.name}},
@{l="PSP";e={($Luns | where CanonicalName -eq (Get-View $_).Info.Vmfs.Extent.diskname).multipathpolicy}}
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Device | %{
$row = "" | Select ESXiIP,ESXiName, VMFSDatastoreName1, VMFSDatastoreName2, Lun, NrPaths
$row.ESXiName = $net.HostName
$row.ESXiIP = $net.VirtualNic.IP -join '|'
$row.Lun = $_.Name
$row.VMFSDatastoreName1 = $esxcli.storage.FullName
$row.VMFSDatastoreName2 = $esxcli.storage.Name
$row.NrPaths = $_.Group.Count
$report += $row
}
}
$report | Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for the suggestion.
$esxName = 'esx1','esx2','esx3'
$report= @()
$esxlist = Get-VMHost -Name $esxName
foreach( $esx in $esxlist){
$esxcli = Get-EsxCli -VMHost $esx
$hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select -ExpandProperty Name
$LUNs = Get-ScsiLun -VmHost $esx
$net = Get-VMHostNetwork -VMHost $esx
$report = Get-Datastore -VMHost $esx | Where type -EQ VMFS | select @{l="host";e={$esx.name}},
@{l="LUN";e={$_.ExtensionData.Info.Vmfs.Extent.diskname}},
@{l="Datastore Name";e={$_.name}},
@{l="PSP";e={($Luns | where CanonicalName -eq (Get-View $_).Info.Vmfs.Extent.diskname).multipathpolicy}}
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Device | %{
$row = "" | Select ESXiIP,ESXiName, VMFSDatastoreName1, VMFSDatastoreName2, Lun, NrPaths, NrVM
$row.ESXiName = $net.HostName
$row.ESXiIP = $net.VirtualNic.IP -join '|'
$row.Lun = $_.Name
$row.VMFSDatastoreName1 = $esxcli.storage.FullName
$row.VMFSDatastoreName2 = $esxcli.storage.Name
$row.NrPaths = $_.Group.Count
$row.NrVM = (Get-View -Id $esx.ExtensionData.Vm -Property Name, Config.Template | where {-not $_.ExtensionData.Config.Template}).Count
$report += $row
}
}
$report | Out-GridView
However, the above result shows two separate data sets that must be combined. Because the result from the above script only the last ESXi servers only in the Out-GridView.
How can I combine the Get-Datastore -VMHost $esx .... command to the $report?
I see the data for all ESXi nodes in the GridView, not just the last one.
To confirm, you want to combine both types of output in one report?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I'd like to combine them into meaningful result in the Out-GridView if possible.
Try like this
Get-VMHost -Name $esxName -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx
$hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select -ExpandProperty Name
$LUNs = Get-ScsiLun -VmHost $esx
$net = Get-VMHostNetwork -VMHost $esx
$ds = Get-Datastore -VMHost $esx | where{$_.Type -eq 'VMFS'}
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Device -PipelineVariable group | ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
ESXiName = $net.HostName
ESXiIP = $net.VirtualNic.IP -join '|'
Lun = $group.Name
Datastore = ($ds | where{$_.ExtensionData.Info.Vmfs.Extent.DiskName -contains $group.Name}).Name
NrPaths = $_.Group.Count
PSP = ($luns | where{$_.CanonicalName -eq $group.Name}).MultipathPolicy
})
}
} | Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Many thanks LucD,
Yes it works great.
LucD, Sorry to get back to you again.
However, the script result is slightly confusing or perhaps not pulling the correct data.
Get-VMHost | Measure-Object returns 9 ESXi servers ranging from 6.0 up to 6.7.
Get-Datastore | Where-Object{$_.Type -eq 'VMFS'} | Measure-Object returns 20 VMFS datastore
Is there any reason why the result only shows the last 5 ESXi servers on my VCenter?
Could it be that the missing ESXi nodes do not have a FC HBA?
How many groups are returned when you do this?
Group-Object -Property {$_.VMHost.Name}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are so spot-on 🙂 once the HBA is online, it can then be shown as the result.
{vmhba65:FibreChannel:offline, vmhba67:FibreChannel:offline}
that does make sense.
Thanks, LucD.