PowerCLI Script- Configure ESXi Host for Connectivity to Nimble iSCSI SAN

By | February 1, 2016

So last week I noticed that a user by the name of Dean had opened a thread on the Nimble Connect forums with some handy PowerCLI to configure an ESXi host to connect to Nimble Storage arrays. I had done the same thing near the end of 2015 when we installed 6 Nimble Storage arrays in our environment, and I was meant to get around to putting it all together in a powershell function/script. Reading Dean’s thread prompted me to revisit this task, and I now have a version 1.0 release of a PowerCLI script that can be run against an ESXi host.


  • The script assumes you have PowerCLI installed, the snapin loaded and you are connected to the relevant vCenter server that has the hosts connected that you want to run the script against (I’ll build this into the script at some point)
  • The script is hard coded to enable and make changes to the iSCSI software initiator only
  • The script modifies some advanced settings of the iSCSI initiator
  • The script is based on you providing two VMNIC Uplink physical adapters to be bound to the new vSwitch
  • The script is based on your providing two IP addresses to use for the VMKernel iSCSI adapters on the ESXi host
  • The script can place the host into maintenance mode before making any changes (recommended) and can also reboot the host after configuration is complete
  • As you will be able to tell, Powershell isn’t my forte, but hopefully this will be of use

Warning: This is a version 1.0 script. I have tested this in my test lab and it works, but your environment will of course please different, so please test this before running in production and make any changes that are required to suit your environment. If there are general issues with running the script or feature requests then please let me know and I will do my best to incorporate them.

The script will perform the following actions:

  1. If the parameter -HostMaintenanceMode is used, places the ESXi host into maintenance mode
  2. Creates a new vSwitch on the ESXi host. If a value for -vSwitchName are not provided, the name of the switch will be vSwitchiSCSI-Nimble
  3. Creates two new port groups on the new vSwitch. If values for -PortGroup1Name/-PortGroup2Name are not provided, the names for the port groups will default to iSCSI-Nimble1 and iSCSI-Nimble2. If a VLAN for iSCSI traffic is provided via -iSCSIVLAN, the VLAN will be configured on the two new port groups
  4. Creates two new VMKernel adapters on the ESXi host. The first is bound to PortGroup1, the second is bound to PortGroup2. IP addresses provided by -iSCSIAddress1 and -iSCSIAddress2 are used for the vmk adapter IP addresses. Subnet mask is by default, or can be changed by using the -iSCSISubnetMask paramter
  5. Sets the NIC teaming policy on the portgroups is, so on portgroup1 uplink1 is active and uplink2 is unused, and on portgroup2 uplink2 is active and uplink1 is unused
  6. Checks to see if the iSCSI software initiator is enabled on the ESXi host, if not, enables it
  7. Inserts the Nimble SAN iSCSI discovery address as a target for the iSCSI Software initiator (provided by -iSCSITargetAddress)
  8. Uses ESXCLI to add the newly created vmkernel adapters to the iSCSI software initiator
  9. Uses ESXCLI to set the iSCSI Advanced settings of LoginTimeout, NoopTimeout and NoopInterval to 30 seconds (see Nimble Storage KB-000087)
  10. If the parameter -RebootHost is used, the host is restarted at the end of the configuration. This is required to apply the timeout changes


Create-NimbleVSwitch.ps1 -HostMaintenanceMode -Hostname ESXi1 -Uplink1 vmnic1 -Uplink2 vmnic2 -vSwitchName iSCSIVSwitch -PortGroup1Name iSCSIPG1 -PortGroup2Name iSCSIPG2 -iSCSIAddress1 -iSCSIAddress2 -iSCSITargetAddress -iSCSIVLAN 800 -MTU 9000 -RebootHost


This command will place the host ESXi1 into maintenance mode, create a vSwitch on host ESXi1, bind vmnic1 and vmnic2 to the switch, create two new port groups names iSCSIPG1/iSCSIPG2, create two VMKernel adapters with the IP addresses and that are associated with the two new port groups.
The portgroups will be tagged with VLAN 800 and the MTU of 9000 will be configured in the relevant spots on the ESXi host. If the iSCSI software intiiator is not installed, it will get installed, the two new vmkernel adapters will be added to the software initiator and the iSCSI Target IP address will be added as a target on the software initiator
The host will reboot after the changes have been applied.

At some stage I will get around to hosting this on a proper repository, for now I’ve used a wordpress plugin to display the code. Hover over the script below and a menu will appear, including the ability to open in a new tab or simply copy the content.



Leave a Reply

Your email address will not be published. Required fields are marked *