VMware Cloud Community
jwblake
Contributor
Contributor
Jump to solution

Remove network adapter from running vm?

Im attempting to remove a network adapter from from a script and the machine needs to stay powered on. I try:

Get-NetworkAdapter $vmname | where { $_.NetworkName -eq "10 Network" } | Remove-NetworkAdapter

Remove-NetworkAdapter : 9/28/2011 3:59:24 PM    Remove-NetworkAdapter        The VM must be in the following state: PoweredOff.
At line:1 char:101
+ Get-NetworkAdapter W7-AutoPrv003 | where { $_.NetworkName -eq "10 Network" } | Remove-NetworkAdapter <<<<
    + CategoryInfo          : InvalidOperation: (PoweredOn:PowerState) [Remove-NetworkAdapter], ViError
    + FullyQualifiedErrorId : Common_SharedParameterHelper_VerifyVmIsInState_VmNotInState,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveNetworkAdapter

i would really thing that there a way to remove the NIC while the VM is powered on?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is with the ReconfigVM_Task method.

$vm = Get-VM MyVM 
$nic = $vm.ExtensionData.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq "Network adapter 2"} $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev
= New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev
.operation = "remove"
$dev
.Device = $nic $spec.DeviceChange += $dev

$vm.ExtensionData.ReconfigVM($spec)

Don't know what the risk is though.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

There is with the ReconfigVM_Task method.

$vm = Get-VM MyVM 
$nic = $vm.ExtensionData.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq "Network adapter 2"} $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev
= New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev
.operation = "remove"
$dev
.Device = $nic $spec.DeviceChange += $dev

$vm.ExtensionData.ReconfigVM($spec)

Don't know what the risk is though.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jwblake
Contributor
Contributor
Jump to solution

Worked like a charm. Thank you!

0 Kudos
DZ1
Hot Shot
Hot Shot
Jump to solution

Off topic; I saw you at VMworld LucD, nice presentation.  Sorry to semi hi-jack the post.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks, glad you enjoyed it.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos