How to get more info from a PowerShell script

I have the following PowerShell script which queries the VMkernels on all VMware hosts in one vCenter and exports the following details:
VMHost,Name,PortGroupName,Mac,IP,SubnetMask, ManagementTrafficEnabled, VMotionEnabled

The script:
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster * | get-vmhost) | Select VMHost,Name,PortGroupName,Mac,IP,SubnetMask, ManagementTrafficEnabled, VMotionEnabled | Sort-Object -Property VMHost, Name

I would also like to get the cluster name from which each host is attached to, so I was wondering, can I get these details from this script or do I have to add more to it?

Here’s everything I can get from this script:
VMotionEnabled : False
FaultToleranceLoggingEnabled : False
ManagementTrafficEnabled : False
IPv6 :
AutomaticIPv6 :
IPv6ThroughDhcp :
IPv6Enabled :
Mtu : 9000
VsanTrafficEnabled : False
PortGroupName : vxw-vmknicPg-dvs-005-1022-7ab0e0cc-6ca1-43ab-976e-abababababab
Id : key-vim.host.VirtualNic-vmk5
VMHostId : HostSystem-host-44587
VMHost : MyHost.MyDomain
VMHostUid : /VIServer=domain\user@vcenter:443/VMHost=HostSystem-host-44587/
DeviceName : vmk5
Mac : 00:50:56:00:00:00
DhcpEnabled : False
IP : 192.20.0.8
SubnetMask : 255.255.0.0
Uid : /VIServer=domain\user@vcenter:443/VMHost=HostSystem-host-44587/HostVMKernelVirtualNic=key-vim.host.VirtualNic-vmk5/
Name : vmk5
ExtensionData : VMware.Vim.HostVirtualNic

Before we proceed - could you format your code and sample output as code please?
Thanks in advance.

To format text as code you simply use the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Without haviong access to or experiences with such an environment I’d expect you to be able to get all information with a loop iterating over all clusters or hosts and combining the desired information with a [PSCustomObject] or with calculated properties. :wink:

Something like this may work:

Get-Cluster *  |
ForEach-Object {
    $Cluster = $_
    $_ | 
        Get-VMHost |
            Select-Object -Property @{Name = 'ClusterName'; Expression = { $Cluster.Name } },
                VMHost, Name, PortGroupName, Mac, IP, SubnetMask, ManagementTrafficEnabled, VMotionEnabled 
} |
Sort-Object -Property ClusterName, VMHost, Name

You may adjust the expression $Cluster.Name for the correct property - as I said I don’t have access or experiences with VMWare clusters.