Deleting a Hyper-V Virtual Switch using WMI and Powershell

Posted by Bink on on November 18 2009, 9:33 AM with no comments
Filed under: ,

HyperVizor.net: Last week, we performed upgrades on our Hyper-V Server 2008 hosts to R2 that serve our Test\Dev environments. The upgrades were very straight forward and uneventful, which is what anyone hopes for when performing any upgrade. However, after the upgrade was complete, it appeared that either a virtual switch had either lost its configuration or failed. It turned out that it was one of those problematic Broadcom NIC’s that we all love so much that failed. So, I unbound the virtual switch that was configured to use the NIC from all VM’s and attempted to delete the switch. I was complimented with a nice error message, informing me that it couldn’t be deleted. So, I did what any good admin would do when the GUI fails us and turned to my trusty command line.

So, when administering Hyper-V using powershell, I use the Hyper-V library that is available from codeplex. Unfortunately, the powershell library doesn’t provide a cmdlet for deleting a virtual switch, so I leveraged a WMI class called “MSVM_VirtualSwitchManagementService”. Then, I used the “Choose-VMSwitch” powershell cmdlet to select the virtual switch for deletion and then deleted the switch. I searched online and found plenty of info on creating a virtual switch using powershell, but nothing regarding how to delete it, so I will walk you through deleting a virtual switch I created called “Demo Virtual Switch”.

In the steps that follow I will show you how to create the WMI object reference, select the virtual switch and finally deleted the selected switch. For this demo

I am running the scripts local to the host with the virtual switch that I want to delete.

Continue: Hypervizor.net Deleting a Hyper-V Virtual Switch using WMI and Powershell

13602 Views
2008 (C) Steven Bink, Bink.nu BV
Microsoft and Microsoft Logo’s are trademarks of Microsoft Corporation.