Continuing to Get Set With PowerCLI and Standard vSwitches

melissa • May 26, 2016 • No Comments

In A Guide to Fumbling Through PowerCLI, we focused on how to get information on a vSphere environment through the VMware vSphere PowerCLI command line interface. Now, since we’ve gotten an idea how to move around our environment with PowerCLI to find out information, let’s focus on configuring our environment with PowerCLI.

When we look at all of the vSphere switch commands we can use within PowerCLI by typing Get-VICommand *switch, we will see some commands prefixed with New and Set.

Before we can set a virtual switch, we first need to create it by using the New-VirtualSwitch command. This command will create a new Standard vSwitch for us. It is simple to find out the syntax for this command by using the get-help feature. The output of Get-Help New-VirtualSwitch tells us exactly the information we need to create our new Standard vSwitch.

Luckily, we have all the information we need to use New-VirtualSwitch to create a new vSwitch on our host, host1.lab.local.  To create vSwitch3 using vmnics 3 and 4 and enabling jumbo frames we can type New-VirtualSwitch -VMHost host1.lab.local -Name vSwitch3 -NumPorts 64 -nic vmnic4,vmnic5 -mtu 9000.

Screen Shot 2016-05-25 at 3.06.29 PM

Once again, PowerCLI is nice enough to tell us we really don’t need to bother with the number of ports on vSphere 5.5 and later. The output tells us our switch has been created, and we can confirm it in vCenter.

Screen Shot 2016-05-25 at 3.37.48 PM

Now, we need some port groups for our switch. We can use Get-VICommand *portgroup to find out what we have available to us.

Screen Shot 2016-05-25 at 3.39.05 PM

In this case, we’re going to want to use New-VirtualPortGroup since we are using a standard vSwitch. We’re going to create a new port group called Servers, on VLAN 33. In order to do this, think about the progression of the command in PowerCLI. We are setting a port group which is on a switch, which is on a host. We can use the command Get-VMHost host1.lab.local | Get-VirtualSwitch -name vSwitch3 | New-VirtualPortGroup -Name Application33 -VLanID 33.

Screen Shot 2016-05-25 at 3.51.15 PM

We can see it has been created by the PowerCLI output.  Now, what if we wanted to create a VMkernel port for Fault Tolerance on our switch? In this case, we are going to need to use the New-VMHostNetworkAdapter command, which has quite a number of attributes available (which we can see by issuing Get-Help New-VMHostNetworkAdapter).

Screen Shot 2016-05-25 at 3.59.08 PMAfter reading what we can do with the command, we can type New-VMHostNetworkAdapter -VMhost host1.lab.local -PortGroup FaultTolerance -VirtualSwitch vSwitch3 -IP -SubnetMask -FaultToleranceLoggingEnabled $True to add our VMkernel port.

Screen Shot 2016-05-25 at 4.06.57 PM

PowerCLI will tell us it has created vmk5 to our specifications after the command has finished running. If we check in vCenter, we will see our switch has the Application33 port group and FaultTolerance port group with vmk5 on it.

Screen Shot 2016-05-25 at 4.08.49 PM

This is just one illustration of using PowerCLI to for a common task, configuring a standard virtual switch.  There are many ways to issue and chain commands within PowerCLI, so you may end up achieving the same results using slightly different commands.  Stay tuned for more examples on how to fumble your way through PowerCLI.


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