VMware Cloud Community
Ross_Walter
Contributor
Contributor

How to get IP from a VMkernel port please

hi!

I am writing a script to get the IP address and subnet mask for a VMkernel port (NFS ports for storage connectivity) for our host servers, to save their config prior to upgrading to v4.1. the script is almost done but I'm having difficulties with some parts of my script. For example:

   #get the NFS VMkernel port IP address details for each host
   $NFSportgroups = Get-VirtualPortGroup -vmhost $hostsvr | Where {$_.name -match "nfs-"}   # our NFS port names are preceeded with "nfs-"

   foreach ($pg in $NFSportgroups)
   { 
      $NFSip = ??

      $NFSsubnet = ??
   }

Similarly, I'm having difficulties getting a host server IP, subnet, gateway and VMotion IP for ESXi4 hosts - my script works fine for ESX3.5 hosts, so please provide assistance with the code I need for this too!

thanking you in advance!

Ross

Tags (4)
0 Kudos
3 Replies
ykalchev
VMware Employee
VMware Employee

Hi,

In order to get VMKernel IP information you need to examine VMKernel virtual netwrok adapter using Get-VMHostNetworkAdapter cmdlet:

Get-VMHostNetworkAdapter -VMKernel -vmhost $hostsvr | Where {$_.PortGroupName -match "nfs-"}

Regards,

Yasen Kalchev

PowerCLI Dev team

Yasen Kalchev, vSM Dev Team
0 Kudos
LucD
Leadership
Leadership

The answer to the 2nd question is similar

Get-VMHostNetworkAdapter -VMHost $hostsvr | where {$_.PortgroupName -like "Management*"}

Btw I think Yasen's line should say

Get-VMHostNetworkAdapter  -VMKernel -vmhost $hostsvr | Where {$_.PortgroupName -match "nfs-"}

Update: I see Yasen corrected the line

Message was edited by: LucD


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

0 Kudos
avlieshout
VMware Employee
VMware Employee

There's a small error in Yasen's example. The code should read:

Get-VMHostNetworkAdapter -VMKernel -VMHost $vmhost | Where {$_.PortGroupName -match "nfs-"}

why not create an overview for all VMkernel ports, so you have ESXi management ports too, in one run. Simply remove the Where statement.

Get-VMHostNetworkAdapter -VMKernel -VMHost $vmhost | Select Name,PortGroupName,IP,SubnetMask

Arnim van Lieshout Blogging: http://www.van-lieshout.com Twitter: http://www.twitter.com/avlieshout If you find this information useful, please award points for "correct" or "helpful".
0 Kudos