-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

PowerCLI Cookbook
By :

One of the first things to be completed against a new ESXi installation is network configuration. Network configuration consists of several things on an ESXi host—first would be to configure the additional management interfaces of the host for VMotion, Fault Tolerance logging, vSphere Replication, and VSAN traffic.
To begin this recipe, you will need to open a PowerCLI window, connect to an ESXi host, and load a VMHost
object into a variable. The example uses $esxihost
as the variable for the VMHost
object.
On installation, ESXi has a single Network Interface Card (NIC) labeled eth0
that is connected to a VMware Standard—vSwitch. The vSwitch has two port groups created: one labeled Management Network for management traffic and the other is labeled VM Network. The Management Network is a vmkernel port with the IP defined on the console attached to it.
In this example, our host contains six 10 Gigabit NICs that will connect the host to the network. You will define two additional vSwitches with two physical ports attached to each for redundancy. The additional vSwitches will handle storage and replication traffic on one and VM traffic on the other.
Best practices of vSphere networking are far beyond the scope of this book. The network layout shown in the preceding diagram is not an endorsement of a particular layout and is for illustration purposes to show the PowerCLI cmdlets used to configure networking on ESXi.
vSwitch0
. The first cmdlet shows you the properties of this virtual switch and the second shows you the port groups associated with that vSwitch. To do this, review the output of the two PowerCLI cmdlets:$esxihost | Get-VirtualSwitch $esxihost | Get-VirtualPortGroup –VirtualSwitch vSwitch0
$esxihost | Get-VirtualPortGroup -Name "VM Network" | Remove-VirtualPortGroup –Confirm:$false
Get-VirtualPortGroup
and Remove-VirtualPortGroup
cmdlets to change the confirmation. When executed, you will receive either a confirmation or an error. If the port group is connected to or in use by a VM, you will receive an error message. Once you remove the VM Network port group, the next step is to add an additional vmkernel port that will be used for vMotion.While this is outside the scope of this book, there are many different ideas for the best design of VMware networking. Most administrators agree that Management traffic and vMotion traffic should be separated, but with increasing speeds and capabilities of NICs today, it's common to see them sharing the same virtual switch. Administrators will set the Management traffic to be active on the first NIC and vMotion to be active on the second NIC. The two traffic streams will only be on the same NIC in a failover situation.
New-VMHostNetworkAdapter
cmdlet and pass in the name of the port group, the virtual switch, and the IP information. You will also pass in a parameter to specify that this vmkernel port should be used for VMotion as follows:$esxihost | New-VMHostNetworkAdapter -PortGroup "VMotion Network" -VirtualSwitch vSwitch0 -IP 192.168.50.241 -SubnetMask 255.255.255.0 -VMotionEnabled $true
Set-NicTeamingPolicy
cmdlet. You can see in the following two commands that the active and standby NIC assignments are opposite between the two port groups:$esxihost | Get-VirtualPortGroup -Name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic0 –MakeNicStandby vmnic1 $esxihost | Get-VirtualPortGroup -Name "VMotion Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic1 –MakeNicStandby vmnic0
$esxihost | Get-VirtualPortGroup -Name "VMotion Network" | Set-VirtualPortGroup –VlanID 50
$esxihost | Get-VMHostNetworkAdapter
The Get-VMHostNetworkAdapter
cmdlet displays all of the vmkernel ports along with all of the physical NICs present on the host.
New-VirtualSwitch
cmdlet to provision the new virtual switch. This cmdlet provisions the vSwitch with its uplinks, but it's currently an island with no connectivity for Management or virtual servers:$esxihost | New-VirtualSwitch -Name vSwitch1 -Nic vmnic2,vmnic3
$esxihost | New-VMHostNetworkAdapter -PortGroup "Storage Network" -VirtualSwitch vSwitch1 -IP 192.168.100.241 -SubnetMask 255.255.255.0 -VsanTrafficEnabled $true $esxihost | Get-VirtualPortGroup -Name "Storage Network" | Set-VirtualPortGroup –VlanID 100 $esxihost | New-VMHostNetworkAdapter -PortGroup "FT Logging Network" -VirtualSwitch vSwitch1 -IP 192.168.200.241 -SubnetMask 255.255.255.0 -FaultToleranceLoggingEnabled $true $esxihost | Get-VirtualPortGroup -Name "FT Logging Network" | Set-VirtualPortGroup –VlanID 200
Set-NicTeamingPolicy
cmdlet:$esxihost | Get-VirtualPortGroup -Name "Storage Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic2 –MakeNicStandby vmnic3 $esxihost | Get-VirtualPortGroup -Name "FT Logging Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic3 –MakeNicStandby vmnic2
$esxihost | New-VirtualSwitch -Name vSwitch2 -Nic vmnic4,vmnic5
New-VirtualPortGroup
doesn't allow any pipeline input, so you will need to specify the server as a parameter instead of passing it through the pipeline:New-VirtualPortGroup -Name "Infrastructure Network" -VirtualSwitch vSwitch2 -VLanId 1 -Server 192.168.0.241 New-VirtualPortGroup -Name "Application Network" -VirtualSwitch vSwitch2 -VLanId 2 -Server 192.168.0.241
In this example, you will work with the VMHost
object to enumerate and identify the existing configuration that is put in place during the installation. From there, you remove the default VM networking configuration, you provision new virtual switches and vmkernel ports to segment traffic, and you enable certain management functions across the vmkernel ports.
While most of the configuration covered in this section deals with the initial configuration of a host, some of the concepts are repeated more often. For instance, if you have a multi-node cluster and you're adding a new virtual machine network, you'll use the New-VirtualPortGroup
cmdlet often. As you have seen in previous examples, you can easily create an array of ESXi hosts—either by using Get-VMHost
in vCenter or by manually specifying a list of hosts—and then connect and provision the same port group on many hosts, quickly. This would mean big time savings and less potential for manual error when compared to manually clicking on each through the GUIs to configure the new port group on each host in the cluster.
By also using the Set-NicTeamingPolicy
cmdlet, you can set a preferred uplink port for each port group and put the other NIC into standby mode. This allows us to keep the Management and vMotion and the Storage and Fault Tolerance traffic separated so they will not cause the performance of one another to be degraded.
In this recipe, you focused on VMware Standard vSwitches. Users with Enterprise Plus licensing also have the option of using VMware Distributed vSwitches which have their own set of cmdlets to manage and configure these advanced virtual switches.
Change the font size
Change margin width
Change background colour