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?
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
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
Worked like a charm. Thank you!
Off topic; I saw you at VMworld LucD, nice presentation. Sorry to semi hi-jack the post.
Thanks, glad you enjoyed it.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference