Hello guys,
we need to change the configuration of our managment network to a different vlan and a different IP, Gatway, etc. Is there a way to do it with powershell?
I find the the command 'set-vmhostnetworkadapter' but there it is only possible to change IP and subnet. How can I change at the same state the Gatway and the VLAN?
Thanks for your help.
Christian
There is currently not one cmdlet that lets you do it all in one go.
The following script changes the IP address, the subnet mask, the console default gateway and the VLAN of the service console with the name defined in $tgtConsole.
!! CAUTION: changing the console might make your ESX unreachable from the VC and will oblige you to go into the ESX console and use the esxcfg-* commands !!
$tgtConsole = <service console portgroupname> # Ex "Service Console" $esxHost = <ESX-hostname> $esxImpl = Get-VMHost $esxHost $hn = $esxImpl | Get-VMHostNetwork $pg = $esxImpl | Get-VirtualPortGroup | where {$_.Name -eq $tgtConsole} # Console gateway Set-VMHostNetwork -Network $hn -ConsoleGateway 192.168.111.1 # IP & subnet $esxImpl | Get-VMHostNetwork | ` %{foreach($cNic in $_.ConsoleNic){if($cNic.PortGroupName -eq $tgtConsole){$cNic}}} | ` Set-VMHostNetworkAdapter -IP 192.168.112.33 -SubnetMask 255.255.240.0 # VLAN foreach($vnic in $pg){ Set-VirtualPortGroup -VirtualPortGroup $vnic -VLanId 1234 }
Updated: the previous version changed all service consoles to the same IP addr, not advisable of course !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your helpLucD.
I think we will do the following create an new service console interface with the new IP and the new VLAN. Then change the Default gateway and delete later the "old" network. Maybe we rename the newly created interface to the old one.