VMware Cloud Community
DroppedAtBirth
Contributor
Contributor
Jump to solution

Change or Set Network on Network Adapter

I am currently setting up VM's via CloneVM_Task and using VirtualMachineRelocateSpec to customize the setup. One thing I haven't been able to figure out is how to set the Network for each network adapter during setup. If there is a way to do this using the VirtualMachineRelocateSpec please let me know. For now I am trying to set the network after the setup is complete, which works for a vm with one networkadapter just fine. Unfortunately Get-NetworkAdapter and Set-NetworkAdapter don't provide much support for working with multiple adapters, or maybe I am missing something, still learning the VI-toolkit and PS. Get-NetworkAdapter returns all adapters for the vm, so I can't easily use Set-NetworkAdapter without updating all the network adapters on the vm.

The following code works fine for a vm with one adapter, but I have yet to figure out how to update just one adapter if the vm has more than one adapter.



Set-NetworkAdapter -NetworkAdapter ( Get-NetworkAdaptervm $vm ) -NetworkName "V1063" -Confirm:$false


0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

You might be able to do that with a customization spec or relocation spec, but if you want to just change things after the fact you could always do something like

$vm | Get-NetworkAdapter | where { $_.Name -eq "Network Adapter 1" } | Set-NetworkAdapter -NetworkName "Net 1" -Confirm:$false
$vm | Get-NetworkAdapter | where { $_.Name -eq "Network Adapter 2" } | Set-NetworkAdapter -NetworkName "Net 2" -Confirm:$false

View solution in original post

0 Kudos
5 Replies
admin
Immortal
Immortal
Jump to solution

You might be able to do that with a customization spec or relocation spec, but if you want to just change things after the fact you could always do something like

$vm | Get-NetworkAdapter | where { $_.Name -eq "Network Adapter 1" } | Set-NetworkAdapter -NetworkName "Net 1" -Confirm:$false
$vm | Get-NetworkAdapter | where { $_.Name -eq "Network Adapter 2" } | Set-NetworkAdapter -NetworkName "Net 2" -Confirm:$false

0 Kudos
DroppedAtBirth
Contributor
Contributor
Jump to solution

Works great, thanks.

0 Kudos
nik-O
Contributor
Contributor
Jump to solution

Hello,

how can i do the sqme thing if the network label comes from a dvSwitch?

I tried the same trick but it gives an error : the network doesn't exist. If i change the network manually , i can see "dv-Prod" in the network settings of the VM .

But then, if i display the Get-NetworkAdapter object, i have " " in the networkname field !!

thanks Smiley Happy

0 Kudos
mikep
Contributor
Contributor
Jump to solution

Hi nik-O,

any success in doing this? I'm currently trying the same thing...

thanks

0 Kudos
ICT-Freak
Enthusiast
Enthusiast
Jump to solution

Same problem here. Does anyone have a solution for this?

0 Kudos