I am moving VMs from one vCenter to another. Since we use distributed port groups, the network adapters show up as "invalid backing". For VMs with a single adapter it is easy to update with a script. What I would like to do is update all the network adapters via a script.
I am thinking there could be a couple of different ways. The VMs obviously have Network adapter 1, Network adapter 2, etc. Also the MAC address stays the same. I can't figure out any commands that work by changing the network connection based on MAC. I was able to use the following which is fine for the first adapter.
Get-VM VM | Get-NetworkAdapter | select -First 1 | Set-NetworkAdapter -NetworkName Public-Network
That changes just Network adapter 1. I could also use the -Last switch to change the last adapter. But we have VMs with 3 and 4 NICs.
I found an example on VMware's website for modifying an adapter based on MAC, but it doesn't seem to work.
Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress '00:50:56:a1:00:00' -WakeOnLan:$true
I figured just change -WakeOnLan to -NetworkName and I would be good, but any combination of the "Set-NetworkAdapter -MacAddress" command throws the error "The MAC address is invalid or is not in the valid range 00:50:56:00:00:00 - 00:50:56:3F:FF:FF." This doesn't really make any sense since the MAC is right.
Any suggestions?