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.
To continue learning about PowerCLI, I want to now focus on PowerCLI for the distributed virtual switch. We will see differences with this and working with standard virtual switches. The biggest difference is going to be the use of the
new-vdswitch commands, as well as the rest of the VMware vSphere distributed virtual switch PowerCLI commands in the
Using PowerCLI to Configure Distributed Virtual Switches in VMware vSphere
What if you did not know to use
get-vdswitch to find out if you had any distrinbuted virtual switches on your VMware vSphere hosts? Looking back on our work with standard virtual switches, we know we can find out the PowerCLI commands we will need to use by issuing
Get-VICommand *switch, since we know it involves the switch on a vSphere host.
This time we want to focus on the VDSwitch commands, which will mange our distributed virtual switches. Just think of adding the D for a distributed virtual switch. If you want to manage distributed virtual switches from a command line, PowerCLI is 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.
Using Get-VDSwitch to List Distributed Virtual Switches
It turns out we have a number of VMware vSphere distributed virtual switches 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.
Removing Distributed Virtual Switches With PowerCLI
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 this by looking at vCenter.
This time it worked successfully, and it did not ask us for a confirmation before removing the switch.
Create a New Distributed Virtual Switch With PowerCLI
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.
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.localAs we can see, this PowerCLI command added a host to the dvswitch. To verify the host has been added to the dvswitch, we can also use a PowerrCLI command. The command to do this is our
Get-VDSwitch command we discovered earlier.
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!).
The big lesson here is the the commands are slightly different when working with vSphere Standard and vSphere Distributed virtual switches. Luckily, it is easy to fumble through PowerCLI using the built in help features in order to figure out the differences
This article is part of the Fumbling Through PowerCLI Series.
Part 1 – A Guide to Fumbling Through PowerCLI
Part 2 – Continuing to Get Set With PowerCLI and Standard vSwitches
Part 3 – Get Set With PowerCLI and Distributed Virtual Switches, Part 1