1

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 ??

John John
  • 379
  • 1
  • 4
  • 12
  • Presumably you want the Host's MAC & IP address? – GregL Aug 18 '15 at 14:56
  • this this a hypervisor server,, and I need to get its ip , mac – John John Aug 18 '15 at 14:58
  • and why when I write Get-VMHost I got "localhost" under the Networkinfo column ? – John John Aug 18 '15 at 15:00
  • `and why when I write Get-VMHost I got "localhost" under the Networkinfo column ?`, because that's what configured on the host (regardless of what's setup in DNS), as stated [here](http://serverfault.com/a/711592/266218). – GregL Aug 18 '15 at 15:02

1 Answers1

1

You'd probably want to use the Get-VMHostNetworkAdapter cmdlet.

In particular, using the -VMKernel switch to only get the host's management interfaces.

Something like this:

Get-VMHost <hostname> | Get-VMHostNetworkAdapter -VMKernel
GregL
  • 9,370
  • 2
  • 25
  • 36
  • ok this worked well thanks a lot. but to improve performance can I combine the "Get-VMHost" & "Get-VMHost | Get-VMHostNetworkAdapter -VMKernel " into one script. so I can get the prevoiuse info + the networkinfo instead of having to run two separate scripts ? – John John Aug 18 '15 at 15:54
  • I'm sure you can. You'd need to loop through all the hosts and create a new object with just the properties you want, append that object to an array and then print the array. Something like [this](http://kunaludapi.blogspot.ca/2014/11/powercli-vmhost-esxi-server-inventory.html) – GregL Aug 18 '15 at 16:25