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
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
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
Works great, thanks.
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
Hi nik-O,
any success in doing this? I'm currently trying the same thing...
thanks
Same problem here. Does anyone have a solution for this?