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.

  • Pingback: DotNetKicks.com

  • Oxigen

    Get-AzureVM : A positional parameter cannot be found that accepts argument ‘$null’.

    At line:1 char:7

    + $vm = Get-AzureVM sgp1 .Import-AzureEndpointsFromCSV.ps1 $vm chatserverEndpoint …

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidArgument: (:) [Get-AzureVM], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.WindowsAzure.Management.ServiceManagement.IaaS.Get

    AzureVMCommand

  • Oxigen

    I get error when importing. need Help!

    Get-AzureVM : A positional parameter cannot be found that accepts argument ‘$null’.

    At line:1 char:7

    + $vm = Get-AzureVM sgp1 .Import-AzureEndpointsFromCSV.ps1 $vm chatserverEndpoint …

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidArgument: (:) [Get-AzureVM], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.WindowsAzure.Management.ServiceManagement.IaaS.Get

    AzureVMCommand

    • Sandrino Di Mattia

      You need to separate this over 2 lines. First you call $vm = GetAzureVM xxx and then you call .Import-AzureEndpointsFromCSV.ps1

  • fajarramd

    Can you explain the steps for calling that script? I am not familiar using the powershell

  • SamP

    Sandrino – great post. I have very little experience with PowerShell so I’m a bit confused about the parameter section. When I call the script from within PS I get:

    Unable to find type [Microsoft.WindowsAzure.Management.ServiceManagement.Model.PersistentVMRoleContext]: make sure that the assembly containing this type is loaded.

    + CategoryInfo : InvalidOperation: (Microsoft.Windo…ntVMRoleContext:TypeName) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : TypeNotFound
    Any ideas?

  • http://twitter.com/petersdp Dave Peters

    Thanks, this just saved me a lot of time!