Glad to hear. You're very welcome.
If you find the answer helpful, please click on the RECOMMEND button.
Original Message:
Sent: May 09, 2025 10:50 AM
From: Tom Lee
Subject: Code to delete vNIC on VM during VM provisioning in Orchestrator
Thanks for the additional code. It worked perfectly once the correct device.key was inputted.
Much appreciated!
Tom
Original Message:
Sent: May 09, 2025 03:55 AM
From: WhiteForEver
Subject: Code to delete vNIC on VM during VM provisioning in Orchestrator
Hi, Tom.
You can take this example from my repo. It will loop over network devices and return them as an object. Therefore, you can check each NIC (by labels or any other property) and find one you want to remove.
------------------------------
If you find the answer helpful, please click on the RECOMMEND button.
Please visit my blog to get more information: https://clouddepth.com
Original Message:
Sent: May 08, 2025 10:54 AM
From: Tom Lee
Subject: Code to delete vNIC on VM during VM provisioning in Orchestrator
Thanks for the code and explanation. How do you go about getting the `deviceChange[0].device.controllerKey' and `deviceChange[0].device.key` for Network adapter 2?
Tom
Original Message:
Sent: May 08, 2025 02:44 AM
From: WhiteForEver
Subject: Code to delete vNIC on VM during VM provisioning in Orchestrator
So,
this is a minimum working code:
var spec = new VcVirtualMachineConfigSpec();var deviceChange = new Array();deviceChange[0] = new VcVirtualDeviceConfigSpec();deviceChange[0].device = new VcVirtualVmxnet3();deviceChange[0].device.key = 4000;deviceChange[0].operation = VcVirtualDeviceConfigSpecOperation.remove;spec.deviceChange = deviceChange;spec.virtualNuma = new VcVirtualMachineVirtualNuma();vm.reconfigVM_Task(spec);
A few comments:
- `vm` - is a VcVirtualMachine object.
- This code will work only if type of the NIC is VMXNET3.
- This code will work only if there is only one NIC.
To make this code more generic, it is worth to cover:
- Convert this code into a function/s.
- All NIC types.
- Check if there are multiple NICs. If so, remove the required one by getting first proper deviceController ID and setting it into `deviceChange[0].device.controllerKey = XXX`. The same for `deviceChange[0].device.key`.
If there is only one NIC:
- default `deviceChange[0].device.key` is 4000.
- default `device.controllerKey` is 100.
PS. If `device.controllerKey` is not provided, it will always remove the first NIC.
Please let me know if you need more details.
------------------------------
If you find the answer helpful, please click on the RECOMMEND button.
Please visit my blog to get more information: https://clouddepth.com
Original Message:
Sent: May 07, 2025 12:38 PM
From: WhiteForEver
Subject: Code to delete vNIC on VM during VM provisioning in Orchestrator
Hi,
I think I have something similar. If it's not urgent, give me some time. I will try to find it.
------------------------------
If you find the answer helpful, please click on the RECOMMEND button.
Please visit my blog to get more information: https://clouddepth.com
Original Message:
Sent: May 07, 2025 11:59 AM
From: Tom Lee
Subject: Code to delete vNIC on VM during VM provisioning in Orchestrator
Hi,
Does anyone have code to delete a vNIC on a VM during VM provisioning in Orchestrator. Our templates contain multiple vNICs to accommodate various builds. Some builds do not require the additional vNICs and would like them removed during the provisioning process in Orchestrator.
Thanks!
Tom