Bezar
Contributor
Contributor

Change ESXi managment ip and vlan id for managment network by script/commands

Hi All

I want to Change ESXi managment ip and vlan id for managment network by script/commands at same time.

How to combaine those commands in to one in powershell? without losing connection to host in between commands

Directly connected to host via powershell

changing ip

$esxcli = Get-VMHost | Get-EsxCli -v2

$esxcliset = $esxcli.network.ip.interface.ipv4.set

$args = $esxcliset.CreateArgs()

$args.interfacename = 'vmk0'

$args.type = 'static'

$args.ipv4 = '192.168.248.136'

$args.netmask = '255.255.255.0'

$esxcliset.Invoke($args)

changeing VlanID

Get-VMHost | Get-VirtualPortGroup -Name "Management Network" | Set-VirtualPortGroup -Name "Management Network" -VLanID 20

0 Kudos
3 Replies
depping
Leadership
Leadership

moving this to PowerCLI

0 Kudos
LucD
Leadership
Leadership

Afaik, that is not possible.
When you change the IP address, you will have to reconnect.


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

0 Kudos
Bezar
Contributor
Contributor

yes. It disconnects as soon as we change IP address. Currently the Esxi is on Trunk port i.e different vlan and IP address i.e (172.17.xx.xx on vlan 1000). we might be getting different vlan and different network (196.168.248.xx on vlan 20).

The current script I am able to execute commands to change IP address but we get trunk port we need to mention the trunk port new vlan ID as well. So I am able to change either IP address or vlan only. Is there any way Where I can change IP address and Vlan as the same time ?

vlan : 1000

Ipaddress : 172.17.xx.xx

2. Required network range Trunk port

Required scenario

vlan : 20

Ipaddress: 192.168.248.xx

i need to change both at same time without losing connection to the host.

i understand i have to reconnect to new ip once ip changed.

0 Kudos