Automate NSX Logical Switch Creation Using PowerNSX

By | August 8, 2017

Automate NSX Logical Switch Creation Using PowerNSX

This is a post about how to mass create logical switches for VMware NSX. First we will show how to create NSX Logical Switches using the GUI. While easy enough, when it comes to very large deployments requiring hundreds or even thousands of logical switches for VXLAN/Layer 2 broadcast domain segmentation, a faster method would be idea.

First, this tutorial will require PowerCLI and PowerNSX to be installed on your system. If you’ve never installed PowerNSX, use the following link from the PowerNSX GitHub website for the Windows Installer. PowerNSX Windows Installation Link

Create NSX Logical Switch in vSphere Web Client

1. Go to “Networking and Security” and get to the NSX Home Page. Click the “Logical Switches” Tab.

2. Click the “+” icon. Give your logical switch a Name, Description. Select the Desired Transport Zone. Choose the desired replication mode, and desired settings for IP Discovery and MAC Learning. Click “OK” when done.

And that’s it. Your new logical switch has been created.

Pretty easy right. But again the theme of this blog is automation and scale. What happens when we need to create 50, 100, 500, 2000 logical switches? Clicking through those menus will likely get old pretty quickly. Now lets look at mass creating Logical Switches using a custom script for Power NSX.

Create Multiple NSX Logical Switches using PowerNSX. 

1. Download the script and csv file from the zip file below. The script is also shown below for easy copy and paste if desired.

PowerNSX_LogicalSwitch

 

2. Unzip the file and open the Logical_Switch_Creation csv file. Enter the names of the desired logical switches in the csv file. In this example we will create 54 logical switches representing their respective VXLAN. Save the .csv file and exit.

3. Now edit the “NSX_Create_Logical_Switch.ps1” file. You want to open the file in the Windows PowerShell ISE windows. 

4. Edit the variables in lines 6 through 11 to match your environment. Edit line 13 to point the location of the logical_switch_creation csv file on your machine. Also Note lines 21 and 22 if you want to change the logical switch replication mode from Unicast, Multicast or Hybrid. In this example, we will leave the replication mode as Unicast.  Save and close when finished.

5. Launch PowerCLI and browse to the location of the script. My script and csv file is located in the c:\work\nsx_powernsx directory.

6. Execute the NSX_Create_Logical_Switch.ps1 file by typing “./NSX_Create_logical_Switch.ps1”. ( Make sure the PowerShell ExecutionPolicy is set to Unrestricted before running the file if it’s not already. “Set-ExecutionPolicy Unrestricted” ) This will proceed to create all of the desired logical switches.

Now if we check the VMware Web Console, we can see all of our newly created NSX logical switches.

And that’s it. We have just create 54 logical switches for NSX. Using this method, we could plan for a massive deployment by getting logical switch/VXLAN names pre-deployment. At deployment we can run this script and get the logical switching portion of the NSX environment setup quickly and efficiently. Thanks for reading.

 

 

Leave a Reply

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