Powercli Script to remove Virtual Network adapter from a Virtual Machine

Powercli Script to remove Virtual Network adapter

# Import the PowerCLI module
Import-Module VMware.PowerCLI
# Connect to vCenter server
Connect-VIServer -Server vcenter.example.com -User administrator@vsphere.local -Password mypassword
# Define the virtual machine
$vm = Get-VM -Name "myvm"
# Get the virtual network adapter to remove
$vnic = Get-NetworkAdapter -VM $vm | Where-Object {$_.Name -eq "Network Adapter 1"}
# Remove the virtual network adapter
Remove-NetworkAdapter -NetworkAdapter $vnic -Confirm:$false
# Disconnect from vCenter server
Disconnect-VIServer -Server vcenter.example.com -Confirm:$false

This script first imports the PowerCLI module and then connects to the vCenter server. It then defines the virtual machine and retrieves the virtual network adapter to remove using the Get-NetworkAdapter cmdlet. Finally, it uses the Remove-NetworkAdapter cmdlet to remove the virtual network adapter from the virtual machine.

You can customize this script to suit your specific needs by modifying the parameters such as the vCenter server connection details, the name of the virtual machine, and the name of the virtual network adapter. You can also use the -Confirm:$false parameter to suppress the confirmation prompt before removing the virtual network adapter.

Leave a Reply

Your email address will not be published. Required fields are marked *