# How to get more info from a PowerShell script

**URL:** <https://forums.powershell.org/t/how-to-get-more-info-from-a-powershell-script/18680>\
**Category:** PowerShell Help\
**Created:** [February 25, 2022, 3:07am UTC](https://forums.powershell.org/t/how-to-get-more-info-from-a-powershell-script/18680 "2022-02-25T03:07:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JDMils](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@JDMils](https://forums.powershell.org/u/JDMils)\
**Post date:** [February 25, 2022, 3:07am UTC](https://forums.powershell.org/t/how-to-get-more-info-from-a-powershell-script/18680/1 "2022-02-25T03:07:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 25, 2022, 3:11am UTC](https://forums.powershell.org/t/how-to-get-more-info-from-a-powershell-script/18680/2 "2022-02-25T03:11:52Z")

</div>

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.

> [@Welcome to the new PowerShell Forums](https://forums.powershell.org/t/welcome-to-the-new-powershell-forums/7/6):
>
> How to format code in [PowerShell.org](http://PowerShell.org) forums. [Codeformatting\_1]

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 25, 2022, 3:18am UTC](https://forums.powershell.org/t/how-to-get-more-info-from-a-powershell-script/18680/3 "2022-02-25T03:18:06Z")

</div>

> [@JDMils](#):
>
> 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?

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. 😉

Something like this may work:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/how-to-get-more-info-from-a-powershell-script/18680/4 "2024-05-16T20:18:13Z")

</div>

Closed on May 16, 2024, 8:18pm UTC


