This article is a continuation of the series I like to call Fumbling Through PowerCLI. My goal is to provide an overview of learning and using PowerCLI by logically working through how to accomplish common administrative tasks. I also like to demonstrate how we can use features within PowerCLI to teach ourselves, and well, fumble through it.
Looking back on our work with standard virtual switches (link), we can find out the command we have to work with by issuing
This time we want to focus on the VDSwitch commands, which will mange our distributed virtual switches. If you want to manage distributed virtual switches from a command line, PowerCLI is really your best option. Remember, the distributed virtual switch control plane resides on the vCetner server, so while there are some esxcli commands to view some characteristics of distributed virtual switches, there is no way to mange them using the esxcli tool on a host.
It turns out we have a number of them in our environment. What if we are just concerned what switches a particular host is connected to? We can use the command
Get-VDSwitch -VMhost host1.lab.local to see what distributed virtual switches host1 is connected to. In fact, let’s see what switches are connected to each host. While we are at it, we might as well take a look at host2.lab.local and see what distributed virtual switches it is connected to.
It seems like we have a number of distributed virtual switches which are not in use. Let’s clean things up a bit by removing the distributed virtual switch named Migrate. To find out how to do this, use the command
We can remove the distributed virtual switch named LACP2 by issuing the command
Remove-VDSwitch -VDSwitch LACP2. PowerCLI will then confirm we want to remove the switch.
Now we are going try to remove the switch named ThisistheFinalvSwitch with the command
Remove-VDSwitch -VDSwitch ThisistheFinalvSwitch -Confirm:$False. Our goal by adding the
-Confirm switch is to skip the confirmation.
Oh no, an error. It looks like ThisistheFinalvSwitch is in use. As we can see above, it is in use by host2.lab.local. We can also confirm in vCenter.
This time it worked successfully, and it did not ask us for a confirmation before removing the switch.
Now, since we have cleaned things up, we are going to create a new distributed virtual switch. First we will use the command
Get-Help New-VDSwitch to find out the syntax and what information we need.As you can see, there are a number of options and and a number of ways to go about creating the switch. One thing to note is the
-ReferenceVDSwitch parameter. This would allow you to create a new switch with the properties of an existing switch.
Some of the next tasks we need to accomplish are adding uplinks and port groups. Stay tuned for the next part of this series to find out how (hint: we’re going to start using variables!).
This article is part of the Fumbling Through PowerCLI Series.
A Guide to Fumbling Through PowerCLI
Continuing to Get Set With PowerCLI and Standard vSwitches
Get Set With PowerCLI and Distributed Virtual Switches, Part 1