VMware Cloud Community
Sebastiancl
Contributor
Contributor

Using the Set-NetworkAdapter PowerShell function - not able when machine is PoweredOn or PoweredOff.

I'm having an issue with the vmware.powercli PowerShell module version: 11.5.0.14912921

I'm trying to set the MAC address and Network of a network adapter attached to a VM.

But i'm unable to do so, due to the machine being PoweredOn or PoweredOff.

Stop-VM 'Machine' |  Get-NetworkAdapter | Set-NetworkAdapter -MacAddress '<MAC Address>' -Connected $true -StartConnected $true -Confirm:$false

Start-VM 'Machine' | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress '<MAC Address>' -Connected $true -StartConnected $true -Confirm:$false

Suspend-VM 'Machine' |  Get-NetworkAdapter | Set-NetworkAdapter -MacAddress '<MAC Address>' -Connected $true -StartConnected $true -Confirm:$false

The only way I'm getting it to work is to Power off the machine, remove NetworkAdapter and create a new one.

Get-VM 'Machine' | Get-NetworkAdapter | Remove-NetworkAdapter -Confirm:$false | New-NetworkAdapter -MacAddress <MAC Address> -NetworkName $VMNetwork -StartConnected -Type e1000e

Error messages attached.

Anyone else having this issue?

0 Kudos
7 Replies
scott28tt
VMware Employee
VMware Employee

Moderator: Moved to PowerCLI


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

The problem might be that you didn't refresh the object in the variable you pipe into Get-NetworkAdapter.
Do a Get-VM after the Stop-VM, or better yet, capture the output of Stop-VM in the variable.


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

0 Kudos
Sebastiancl
Contributor
Contributor

Unfortunetly that's not working either.

$TestMachine = Start-VM $TestMachine

Set-NetworkAdapter -MacAddress 'MAC' -Connected $true -StartConnected $true -Confirm:$false -NetworkName $VMNetwork -NetworkAdapter $(Get-vm $TestMachine | Get-NetworkAdapter)

$Test = Stop-VM $TestMachine

$Test | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress 'MAC -Connected $true -StartConnected $true -Confirm:$false -NetworkName $VMNetwork

As a side note, the machine only has 1 network adapter.

I could try changing the adapter type I guess, from E1000E to a vmxnet3.
I'll get back with the result.

0 Kudos
LucD
Leadership
Leadership

There seems to be a problem with conflicting parameters in the Set-NetworkAdapter cmdlet.

Although the parameterset states that you can use the MacAddress and Connected/StartConnected together, it seems you can't.

The following works for me (it assumes the VM is powered on when the script runs)

$vmName = 'MyVM'

Get-VM -Name $vmName | Stop-VM -Confirm:$false | Get-NetworkAdapter |

Set-NetworkAdapter -MacAddress '00:50:56:b0:d0:dd' -Confirm:$false


Get-VM -Name $vmName | Start-VM -Confirm:$false | Get-NetworkAdapter |

Set-NetworkAdapter -Connected $true -StartConnected $true -Confirm:$false


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

0 Kudos
Sebastiancl
Contributor
Contributor

Well, I'd say that's a bug report..Any ideas of how to start one of those?

I'll try the below in a few minutes.

0 Kudos
LucD
Leadership
Leadership

There isn't currently not really a bug repository I'm afraid.

There are a couple of options though:


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

0 Kudos
Sebastiancl
Contributor
Contributor

Thanks a lot LucD.

I'll ping them on Twitter!
Just as you confirmed, the issue is with the connected parameter when using the MacAddress parameter set.

0 Kudos