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?
Moderator: Moved to PowerCLI
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
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.
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)
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
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.
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
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.