Adding multiple endpoints to your Windows Azure Virtual Machines by using a CSV file

In order to manage endpoints of a Virtual Machine you have 2 options: use the portal or use Powershell. If you use the portal it’s not so easy to add a list or a range or ports, you would need to add these ports one by one. The other way you can manage these endpoints is by writing Powershell scripts and that’s what I did over and over again for the past few months.

What I wanted was some way to easily add endpoints to newly created Virtual Machines. A CSV file would be perfect for this. It’s easy to manage (in Excel for example) and you can create different templates to improve reusability. That’s why I created the Import-AzureEndpointsFromCSV.ps1 script.

With this script you can import 2 types of endpoints:

  • Normal endpoints (not load-balanced)
  • Load-balanced endpoints

Creating a CSV file

So what you would do first is create the endpoints in CSV format. By using Excel it’s actually very easy to duplicate the defined endpoints by dragging the cells down (but you can also use Notepad or any other text editor). The normal endpoints are defined by these columns: Name, Protocol, PublicPort, LocalPort.

The load balanced endpoints need a little more information: Name, Protocol, PublicPort, LocalPort, LBSetName, ProbePort, ProbeProtocol, ProbePath

After defining the endpoints, simply export to a CSV file:

Importing the CSV file

Calling the script and importing the CSV file is very easy. You simply call the script and pass the required parameters:

  • The virtual machine
  • The filename of the CSV file
  • The type of CSV file: NoLB or LoadBalanced

In case you want to add load-balanced endpoints you will need to add those to each virtual machine in the cloud service.

After importing the endpoints you’ll see them showing up in the portal:

And after you imported the load-balanced endpoints for all your machines in the same cloud service you’ll see that these endpoints show up as being load balanced:

The script and the sample CSV files are available on GitHub.

About Sandrino Di Mattia

Sandrino Di Mattia is a Customer Success Engineer at Auth0 and a Microsoft Azure MVP.

  • Mark Vange

    I could not get it to launch so I made a modification and eliminated the type checking, so lines 2-7 now read as follows:


    $vm = $(throw “‘vm’ is required.”),
    [string]$csvFile = $(throw “‘csvFile’ is required.”),
    [string]$parameterSet = $(throw “‘parameterSet’ is required.”)

    Now to launch FIRST:

    $vm = get-azurevm -serviceName YOURSERVICENAME -name YOURVMNAME


    .Import-AzureEndpointsFromCSV.ps1 $vm .yourfile.csv NoLB

    This assumes you have CD’d into the folder that contains both the script file and the csv file .. also, note that the default delimiter on my excel turned out to be the “,” (comma) but the script expects a “;” (semicolon) so you need to make sure you modify the delimiter appropriately.

    That worked great for me on 3/18/2014. Your mileage may vary.

  • Debarghya Dasgupta

    Assuming the above requirement i would personally prefer Powershell to do the trick in more simplified manner. Assuming that i want to Add a range 5000 – 5004 (TCP) , i have written a small powershell script, and it worked :)



    { Get-AzureVM -ServiceName “Server1″ -Name “Server1″ | Add-AzureEndpoint -LocalPort $i -PublicPort $i -Name ServerEndpointName$i -Protocol TCP | Update-AzureVM; $i+=1}

    until ($i -gt 5004 )

    Hope this helps.

    • in2ishun

      I swear to JC on a pogo stick! This actually worked!

      The entire point of the original post takes for granted a number of fluencies and background knowledge about Azure and how to execute powershell scripts inside a simple VM — NONE OF WHICH ARE COVERED!!!

      A simple loop. Perfect! Thanks Debarghya!

  • Guest

    I could not get it to launch so I made a modification and eliminated the type checking:


    $vm = $(throw “‘vm’ is required.”),
    [string]$csvFile = $(throw “‘csvFile’ is required.”),
    [string]$parameterSet = $(throw “‘parameterSet’ is required.”)

    Now to launch FIRST:

    $vm = get-azurevm -serviceName ### -name ###


    .Import-AzureEndpointsFromCSV.ps1 $vm .yourfile.csv NoLB

    That worked great for me. Your mileage may vary.

  • Adam Marshall

    I think I know the solution to this, the script is using ‘;’ as a delimiter, You might be using ‘,’ as a delimiter instead. Switching the script to use ‘,’ as a delimiter should work.

  • Shannon Lowder

    I got an error message when I tried going past 150 ports.

  • emdeane

    Debarghya, your post saved me hours! Thanks

  • Amit Deorukhkar

    Can you send me the script?