VMware Cloud Community
arvindathere
Enthusiast
Enthusiast

vNIC portgroup change using powerCLI command on existing VM

Hi LucD​,

Move-VM fails intermittently while trying to change portgroup on a restored VM. with below error

Object reference not set to an instance of an object.

Went through the communities and found the below post . However this is to change while cloning.

Change vnic-portgroup Assignment during Clone operation

I need to change vnic port group on a existing VM(powered off). How can i change that ?

What spec should i use ? and what parameters needs to be set ? Could you please help ?

Regards,

Arvind

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

When a Move-VM fails due a portgroup change, it is often caused by the portgroup not existing on the ESXi node where the VM is located.
Another problem could be that the restored VM still contains a connection to a specific port on the portgroup.

And that port might not be free or exist.

Did you try with the Set-NetworkAdapter cmdlet after the restore?

Get-VM -Name MyVM |

Get-NetworkAdapter |

Set-NetworkAdapter -NetworkName NewPG -Connected -StartConnected -Confirm:$false


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

Reply
0 Kudos
arvindathere
Enthusiast
Enthusiast

yes  LucD Tried something like this .

Set-NetworkAdapter -NetworkAdapter $adaptor -NetworkName $PortGroup -ErrorAction Stop -WarningAction SilentlyContinue -Confirm:$false

Set-NetworkAdapter Object reference not set to an instance of an object. .Exception.Message

Often the first time ,it fails with above error and upon retry within few seconds , the same command goes through.

All Variables are not null. verified by logging just before the command inside the script.

So i was wondering if there was another way to change ?

Reply
0 Kudos
LucD
Leadership
Leadership

Not really, the thread you pointed to is using the vSphere API methods directly.
But the PowerCLI cmdlet is doing the same calls under the cover.

You could remove the vNIC and add it again.
The problem here would be that the guest OS of the VM will see it as a new NIC, and will require a network configuration inside the guest OS.

Are we talking about portgroups on a DVS or a VSS?


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

Reply
0 Kudos
arvindathere
Enthusiast
Enthusiast

Oh ok. My portgroups are on standard virtual switch.

Reply
0 Kudos
LucD
Leadership
Leadership

After a restore of such a VM, what does the vNIC look like?
Do a (after a restore, and make sure to do the Get-VM as well)

Get-VM -Name MyVM | Get-NetworkAdapter | select *


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

Reply
0 Kudos
arvindathere
Enthusiast
Enthusiast

Done. Here is the output .

MacAddress       : 00:50:56:94:a4:ad

WakeOnLanEnabled : True

NetworkName      : SVT_FedPortGroup

Type             : Vmxnet3

ParentId         : VirtualMachine-vm-4923

Parent           : 0_CentOS_7_auto_01_recovery

Uid              : /VIServer=vsphere.local\administrator@xxxxx/VirtualMachine=VirtualMachine-vm-4

                   923/NetworkAdapter=4000/

ConnectionState  : NotConnected, GuestControl, StartConnected

ExtensionData    : VMware.Vim.VirtualVmxnet3

Id               : VirtualMachine-vm-4923/4000

Name             : Network adapter 1

MacAddress       : 00:50:56:94:8d:0c

WakeOnLanEnabled : True

NetworkName      : VM Network

Type             : Vmxnet3

ParentId         : VirtualMachine-vm-4923

Parent           : 0_CentOS_7_auto_01_recovery

Uid              : /VIServer=vsphere.local\administrator@xxxx/VirtualMachine=VirtualMachine-vm-4

                   923/NetworkAdapter=4001/

ConnectionState  : NotConnected, GuestControl, StartConnected

ExtensionData    : VMware.Vim.VirtualVmxnet3

Id               : VirtualMachine-vm-4923/4001

Name             : Network adapter 2

Reply
0 Kudos
LucD
Leadership
Leadership

That all looks ok.
When you do the Set-NetworkAdapter, can you try that the output from a Get-NetworkAdapater, connected over a pipeline?
Like the example I gave earlier.


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

Reply
0 Kudos
arvindathere
Enthusiast
Enthusiast

Ok. Will try this. LucD . Thank you

Reply
0 Kudos