1

I'm using ESXi 6.0 and PowerCLI. I've created a clone of a production VM:

$Source_VM = Get-VM -Name "MyProductionServer"
$Target_VMHost = Get-VMHost -VM $Source_VM
$Cloned_VM = (New-VM -Name "MyPreProdServer" -VM $Source_VM -VMHost $Target_VMHost)

My MyProductionServer has a static IP address set on the OS side. If I start the $Cloned_VM I will have a duplicate IP on the same subnet. What I would like to do is to DISCONNECT the NIC on the cloned VM before starting this one.

What I've found is:

1) On a powered on VM:

Get-NetworkAdapter -VM $Cloned_VM | Set-NetworkAdapter -Connected:$false -StartConnected:$false -Confirm:$false

This is working but I can't do that because of the state of the cloned VM.

2) Remove the NIC from the VM:

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].Operation = "Remove"
$spec.DeviceChange[0].Device = $Cloned_VM.ExtensionData.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq "Network adapter 1"}
$Cloned_VM.ExtensionData.ReconfigVM_Task($spec)

Source: https://communities.vmware.com/thread/454525

This is working too but it's not exactly what I would like.

I would like to DISCONNECT the current NIC to let me boot the cloned VM, changing the IP address then CONNECT the NIC (+ reboot) to have the cloned VM working with another IP address.

In simple words, I would like to do the 1) on a powered off VM. Is that possible ?

1

So I've tested this on test environment and it's working.

# Saving the NIC
$Saved_NIC = $Cloned_VM.ExtensionData.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq "Network adapter 1"}

# Removing the NIC
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].Operation = "Remove"
$spec.DeviceChange[0].Device = $Saved_NIC
$Cloned_VM.ExtensionData.ReconfigVM_Task($spec)

# Modifying my VM (boot + launch script + poweroff)

# Adding the NIC
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].Operation = "Add"
$spec.DeviceChange[0].Device = $Saved_NIC
$Cloned_VM.ExtensionData.ReconfigVM_Task($spec)

# Boot again my VM and test to reach the internet: WORKING!
Start-VM -VM $Cloned_VM

It seems to be OK, I'll see that later on Pre-Prod environment :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.