Get Set With PowerCLI and Distributed Virtual Switches, Part 1

melissa • June 07, 2016 • No Comments

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, we can find out the command we will need to use by issuing Get-VICommand *switch.

Screen Shot 2016-06-03 at 4.27.35 PM

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 a great 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.

Let’s start by using the command Get-VDSwitch to see if we have any distributed virtual switches in our environment.Screen Shot 2016-06-03 at 4.29.26 PM

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.Screen Shot 2016-06-03 at 4.32.31 PM

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 Get-Help Remove-VDSwitchScreen Shot 2016-06-03 at 4.34.17 PM

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.

Screen Shot 2016-06-05 at 5.13.06 PM

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.Screen Shot 2016-06-05 at 5.25.13 PM

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 this by looking at vCenter.

Screen Shot 2016-06-05 at 5.59.00 PM

After we disconnect the host from the switch, we can try our command again.Screen Shot 2016-06-06 at 9.17.47 AM

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.Screen Shot 2016-06-06 at 9.19.37 AMAs 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.

We’re going to keep things simple for our new distributed virtual switch, and create one using the command new-vdswitch -NumUplinkPorts 2 -Name ProductionApp1 -mtu 9000 -Location Lab.Screen Shot 2016-06-06 at 9.26.23 AM

Now we have our switch. Our next steps are to add a host. We can use the command add-vdsswitchvmhost -vdswitch ProductionApp1 -vmhost host2.lab.localScreen Shot 2016-06-06 at 9.38.49 AM

As we can see our host is now added to our distributed virtual switch.  We can verify this by using the Get-VDSwitch command from earlier.Screen Shot 2016-06-06 at 10.11.04 AM

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

Categories VMware