I have gone around in circles on this, but using PowerCLI I cannot find a way to change a vmkernel NIC's port group AND IP at the same time (actually trying to change to DHCP, but same problem. It seems if you need to change the port group the option to change anything about the IP is not available. So, there is no way to fix this without using a IPMI remote console it seems.
Any suggestions would be appreciated.
Afaik, there is indeed no cmdlet to combine those actions.
It does seem to be possible with the UpdateVirtualNIC API method.
The following snippet is for a vmkernel that is moved from one VDS porgroup to another one.
It should be similar for a VSS based VMKernel, just use the Portgroup property instead of the DistributedVirtualPort property.
$esxName = '<MyESx>'
$vmkName = 'vmkx'
$newPG = '<new-vdPG>'
$esx = Get-VMHost -Name $esxName
$pg = Get-VDPortgroup -Name $newPG
$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem
$spec = New-Object -type VMware.Vim.HostVirtualNicSpec
$spec.Ip = New-Object -TypeName VMware.Vim.HostIPConfig
$spec.IP.Dhcp = $true
$spec.DistributedVirtualPort = New-Object -TypeName VMware.Vim.DistributedVirtualSwitchPortConnection
$spec.DistributedVirtualPort.SwitchUuid = $pg.vdswitch.ExtensionData.Uuid
$spec.DistributedVirtualPort.PortgroupKey = $pg.ExtensionData.Key
$netSys.UpdateVirtualNic($vmkName, $spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I gave this a try and I am hitting an error concerning 'DistributedVirtualPort'. I did not think it would be as simple as replacing that with 'Portgroup', but I gave it a try and that did not work either. I assume I need to use a different type with this line as well:
$spec.DistributedVirtualPort = New-Object -TypeName VMware.Vim.DistributedVirtualSwitchPortConnection
Can't I just not include 'DistributedVirtualPort' in the spec and instead use the 'portgroup' Property? If so, I don't know what type to instantiate.
I updated the script using this instead and I am getting a puzzling error, below. If I just run 'New-Object -TypeName VMware.Vim.HostPortgroup' I can see the structure of the object, but when it is added to '$spec', get-method says it is just string, not the HostPortgroup object.
$spec.Portgroup = New-Object -TypeName VMware.Vim.HostPortgroup
$spec.Portgroup.Key = $pg.ExtensionData.Key
When you use a VSS portgroup, the Portgroup property is indeed just s string.
Place the name of the Portgroup in there, not the Key
Note: you can not use the DistributedVirtualPort property when you use the Portgroup property
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am getting a new error now: The Specified Parameter was not correct: VirtualNic.Specification.Portgroup
Come to think of it, how did you define a VMKernel on a VSS portgroup?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I figured out my mistake and went back to the original script using DistributedVirtualPort, but unfortunately the change timesout and does not seem execute both changes at the same time. Neither the old static IP on the old portgroup or the DHCP assigned IP on the new portgroup are responding.
I will need to go back to my first idea of adding a new vmkernel NIC and removing vmk0. Not ideal, but it will work.
I gave up on this. There appears to be no way to change both the IP of the management vmKernel interface and it's backing port group, on virtual distributed switches, at the same time via any API. You can do it using standard switches, but not vDS.
I had to make all of the changes manually in the DCUI via remote console. It was a pain and there needs to be a better way to do this.