VMware Cloud Community
Sreejesh_D
Virtuoso
Virtuoso

Powrcli to change vmkernel interface name

Hi All,

hope you all doing good.

when we deleted and recreated a vmkernel nic the name automatically changed to the next in the series. It was vmk4 and when recreated it changed to vmk5. Is there a powercli or commandline option to change the name back to vmk4?

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

No rename is possible afaik, but you can remove the incorrect one and recreate it with the desired name.
Something like this for example

$wrongVMK = 'vmkX'
$correctVMK = 'vmkY'

$esxName = 'MyEsx'

$esxcli = Get-EsxCli -VMHost $esxName -V2

$oldVMK = $esxcli.network.ip.interface.list.Invoke() | where{$_.Name -eq $wrongVMK}
$oldVMKIP = $esxcli.network.ip.interface.ipv4.get.Invoke(@{interfacename=$oldVMK.Name})
$oldVMKMgmt = $esxcli.network.ip.interface.tag.get.Invoke(@{interfacename = $oldVMK.Name})

$arg = $esxcli.network.ip.interface.add.CreateArgs()
$arg.interfacename = $correctVMK
if($oldVMK.Portgroup -eq 'N/A'){
  $arg.dvsname = $oldVMK.VDSName
  $arg.dvportid = $oldVMK.VDSPort
}
else{
  $arg.portgroupname = $oldVMK.portgroupname
}
$arg.mtu = $oldVMK.mtu
$arg.macaddress = $oldVMK.macaddress
$arg.netstack = $oldVMK.NetstackInstance
$arg.numrxqueue = $oldVMK.RXDispQueueSize

$argIP = $esxcli.network.ip.interface.ipv4.set.CreateArgs()
$argIP.interfacename = $correctVMK
$argIP.netmask = $oldVMKIP.IPv4Netmask
$argIP.gateway = $oldVMKIP.Gateway
$argIP.type = $oldVMKIP.AddressType.ToLower()
$argIP.peerdns = $oldVMKIP.DHCPDNS
$argIP.ipv4 = $oldVMKIP.IPv4Address

$argMgmt = $esxcli.network.ip.interface.tag.add.CreateArgs()
$argMgmt.interfacename = $correctVMK
$argMgmt.tagname = $oldVMKMgmt.Tags

# Remove incorrect VMKernel interface
$esxcli.network.ip.interface.remove.Invoke(@{interfacename = $oldVMK.Name})

# Create new VMkernel interface with correct name
$esxcli.network.ip.interface.add.Invoke($arg)

# Set IPv4 config for VMK (if using IPv6 this will need change)
$esxcli.network.ip.interface.ipv4.set.Invoke($argIP)

# Set correct service for VMK
$esxcli.network.ip.interface.tag.add.Invoke($argMgmt)


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

Reply
0 Kudos