PowerShell and PowerCLI are such a wonderful tools for so many things. I want to share a very simple 'one-liner' that saved me a good amount of time when removing a bunch of Standard Switches from hosts on various vCenters.
Recently I was tasked with migrating hosts and their VMs on a few vSphere environments from Standard Switches to the Virtual Distributed Switch on their corresponding vCenters; the migration part wasn't hard, hosts were added to VDS, then the VMs were hot migrated using the built-in "Migrate Virtual Machine Networking" option of the VDS. Once all was set and done, the Standard Switches and their port-groups, which there were many, needed to be cleaned up, but manually removing one Switch at the time from several hosts wasn't a smart way of doing it - simple from the GUI yes, but not ideal if you have large amount of hosts with a handful of VSS each. So the one-liner that allowed me to remove all Standard Switches from all nodes at once was:
Remove-VirtualSwitch -VirtualSwitch vSwitch1, vSwitch2, vSwitch3, vSwitch4 -Server vCenterServerName -Confirm:$false
The syntax for this command allows to enter multiple VSS names separated by comas which is key for removing all intended switches in one shot. Parameter -Confirm:$false avoided the prompt for every deletion and the -Server vCenterServerName option is only required if you are connected to more than one vCenter Server on the current PowerCLI session. You should obviously use caution and test before running a command like this against your production vCenter Server, the -WhatIf parameter is very helpful to confirm that what you want to accomplish with the command is what the result will be.