VMware Cloud Community
johnjohnjjj
Contributor
Contributor

unable to get the IP,Mac, and other network info using (Get-VMHost).NetworkInfo

I am using powerCLI verion 5.5, and I wrote the following script:-

Get-VMHost |Export-Csv -Path c:\test.csv -NoTypeInformation UseCulture

I got info for the vmhost such as used memory, build, state ,cpu spped, etc. but for the networkinfo section inside the generated .csv file I got "localhost" instead of the VMHost network info. so I wrote another script as follow to get the ip,mac and other netwrk info:-

(Get-VMHost).NetworkInfo | Export-Csv -Path c:\test2.csv -NoTypeInformation -UseCulture

but I got these info only , where I can not get the IP,MAC of the VMHOst :-

VMHostId   VMHost  VMKernelGateway VMKernelGatewayDevice   ConsoleGateway  ConsoleGatewayDevice   DnsAddress  DnsFromDhcp DnsDhcpDevice   DomainName  HostName   SearchDomain   VirtualSwitch   PhysicalNic ConsoleNic  VirtualNic  Uid IPv6Enabled ConsoleV6Gateway   ConsoleV6GatewayDevice  VMKernelV6Gateway   VMKernelV6GatewayDevice ExtensionData   ExtensionData2 HostSystem-ha-host  ******.intra  172.16.20.1  FALSE localhost  VMware.VimAutomation.ViCore.Interop.V1.Host.Networking.VirtualSwitchInterop[]   VMware.VimAutomation.ViCore.Interop.V1.Host.Networking.Nic.PhysicalNicInterop[] VMware.VimAutomation.ViCore.Interop.V1.Host.Networking.Nic.HostVirtualNicInterop[]  VMware.VimAutomation.ViCore.Interop.V1.Host.Networking.Nic.HostVirtualNicInterop[]  /VIServer=root@****************:443/VMHost=HostSystem-ha-host/VMHostNetwork=/  FALSE  VMware.Vim.HostNetworkInfo  VMware.Vim.HostNetworkSystem

so can anyone advice how I can get the network info the vmhost ? and should this be done as a separate script or I can do this inside my original script Get-VMHost ??

0 Kudos
3 Replies
LucD
Leadership
Leadership

Do you have more than 1 ESXi node in your environment ?

If yes, then (Get-VMHost) will be an array, and there the NetworkInfo property is not known.

You better use a Select-Object with calculated properties, and use the Get-VMHostNetworkAdapter cmdlet, like for example

Get-VMHost |

Select Name,

    @{N='IP';E={$_|Get-VMHostNetworkAdapter -Name vmk0 | Select -ExpandProperty IP}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
johnjohnjjj
Contributor
Contributor

but before running the Get-VMHost i am connecting to a single server , so the Get-VMHost should return the info for a single VMHOst,, is this correct ?

0 Kudos
LucD
Leadership
Leadership

That is correct.

Does the Select produce the info ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos