Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

POWERCLI: VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE

July 10, 2017 06:42PM

In earlier chapter I created new VMKernel adapter using vSphere Web client GUI, Here I am going to perform same steps but using vmware powercli, If you are new to PowerCLI, need to set it up, I am suggesting check my another blog VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP. Open PowerCLI,  Login to the vCenter server or Esxi with commandlet Connect-VIServer vCenterIP_Or_FQDN. Next command is select the ESXi host and store its information in variable, so I can use it again and again for creation of vSwitch and VMKernel adapter. I have provided screenshot to show how powercli commands are mapped to vSphere web client GUI.

$VMhost = Get-VMhost Esxi001.vcloud-lab.com

vsphere vmware powercli connect-viserver, variable, get-vmhost, vcloud-lab.com, vmware web client login to esxi, and vsphere vcenter add vmkernel and standard virtual vswitch

Series Parts
MICROSOFT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV 
POWERSHELL INSTALLING AND CONFIGURING MICROSOFT ISCSI TARGET SERVER
VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE
POWERCLI: VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE
VMWARE ESXI INSTALL AND CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER FOR VMFS VERSION 6 DATASTORE
POWERCLI VMWARE: CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER AND ADD VMFS DATASTORE
VMWARE VCENTER STORAGE MIGRATE/SVMOTION VM AND PORT BINDING MULTIPATHING TESTING
POWERCLI: VIRTUAL MACHINE STORAGE MIGRATE/SVMOTION AND DATASTORE PORT BINDING MULTIPATHING

As this is complete PowerCLI based article I will see how my esxi physical nic adapters are used by vSwitch and which are free. To show the complete list the of Physical VMnics, I am using $vmhost variable and keep using it with piping (combining other cmdlets) for next commands, as It has all the information related to selected host.
$vmhost | Get-VMHostNetworkAdapter -Physical |  Select-Object Name

Get-VMHostNetworkAdapter list all the physical nics as well as VMKernel adapters, As I interested in seeing Physical only I am using syntax with same name -Physical. next result is piped into Select-Object to see the VMNic names only.
$vmhost | Get-VirtualSwitch | Select-Object  Name, Nic

Once I know how many physical Nics I have, I can see which Nics are in used by virtual switches with Get-VirtualSwitch. Here make sure you are using correct Physical NIC. You can also view CDP or LLDP information to determine the correct NIC adapter, It doesn't mean if you have free NIC you can connect it anywhere, you also need to review your backend networking for perfect designing. Here I know my vmnic3 is straight away connected with same storage switch, I am selecting it.

VMware Powercli Get-VMHostNetworkAdapter -physical Select-Object -expandProperty, variable Get-VirtualSwitch vmnic information from esxi host

First oneliner cmdlet creates new standard virtual switch, Command is New-VirtualSwitch and configuration syntaxes are -Name is vSwitch2, Physical -Nic is vmnic3 and -MTU 9000.
$vmhost | New-VirtualSwitch -Name vSwitch2 -Nic vmnic3 -Mtu 9000

Once standard virtual switch is created successfully, I am creating new VMKernel adapter port with New-VMHostNetworkAdapter on the same virtual switch named vSwitch2, here Portgroup is equivalent to name of VMkernel PortGroup, Best practice is to use static IP, It also set Mtu to 9000.
$vmhost | New-VMHostNetworkAdapter -PortGroup iSCSI02 -VirtualSwitch vSwitch2 -IP 172.20.1.11 -SubnetMask 255.255.255.0 -Mtu 9000

This is the last command and setting VLAN ID on VMkernel adapter, Command querying existing VMKernel on the esxi server with Get-VirtualPortGroup and edit it using Set-VirtualPortGroup with -VLANId parameter.
$vmhost | Get-VirtualPortGroup -Name iSCSI02 | Set-VirtualPortGroup -VLanId 202

In case if you are getting error make sure Name, Portgroup and Nic are not in used (duplicate) and you have appropriate privileges to perform this task. Confirm changes under Esxi Server>>Configure tab>>Expand Networking>>virtual Switches, For me all looks good.

vmware powercli New-VirtualSwitch -Name -Nic -Mtu, New-VMHostNetworkAdapter -PortGroup -VirtualSwitch  -IP -SubnetMask -mtu, Get-VirtualPortGroup  -Name, Set-VirtualPortGroup -VLanId, Create virtual switch standard, vlan mtu

Go Back

Comment