Hello,
I have to re-ip a bunch of ESXi hosts into a different subnet. I've got a script that will connect to vCenter, let me select the datacenter, select the host, remove the host from vCenter (as the host is also having a fqdn change), disconnect from vCenter, connect directly to the host and then try to reconfigure the host. I understand it can't be all done in one command, but I'm not sure why it's failing, or what the exact command is. Is it Set-VMHostNetwork or Set-VMHostNetworkAdapter? What I have is this:
$ESXIP = Read-Host "Enter new IP address"
Write-Host "Configure new management network"
Get-VMHost "$ESXhost" | Set-VMHostNetworkAdapter -VirtualSwitch "vSwitch0" -PortGroup "Management Network" -IP "$ESXIP" -SubnetMask "255.255.255.0" -ManagementTrafficEnabled:$true -Confirm:$false | out-null
Write-Host "Configure new DNS servers"
Get-VMHost "$ESXhost" | Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress 8.8.8.8,8.8.8.8 -DnsFromDhcp $false
Write-Host "Change VMkernel Gateway"
$net = Get-VMHostNetwork
$net | Set-VMHostNetwork -VMKernelGateway 1.2.3.4 | out-null
But I always seem to get a failure on the setting of the IP, which of course stops it from doing the gateway:
Set-VMHostNetworkAdapter : Parameter set cannot be resolved using the
specified named parameters.
At C:\Users\emcclure\Desktop\GenScripts\GenUpdateHostIPSettings.ps1:39 char:25
+ ... $ESXhost" | Set-VMHostNetworkAdapter -VirtualSwitch "vSwitch0" -PortG ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VMHostNetworkAdapter],
ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.Host.SetVMHostNetworkAdapter
I'd figure after this I'd either want to reboot the host or somehow get the network to restart and then add it back to vCenter with the new fqdn. But how to get the above to work? Any help appreciated. Thanks in advance.