Monday, May 26, 2014

Adding Endpoints in batch for Microsoft Azure Virtual Machines

For Virtual Machines in Microsoft Azure, you have to create Endpoints in order for traffic to enter your VM.

You can add Endpoints using the Azure Portal, but you can only do it one at a time.  This is very tedious.

You can use Power Shell to add the Endpoints too.

Start > Windows Azure > Windows Azure PowerShell

This will launch the Windows Power Shell with Azure support.
Execute this command to retrieve the "PublishSettingsFile" for your Azure account.

Get-AzurePublishSettingsFile

This will launch the Windows Power Shell with Azure support.
Execute this command to retrieve the "PublishSettings" file for your Azure account.
Save the PublishSettings" file in your root drive for easier access for the next command.
Execute this command to install the certificate into your certificate store and configure your subscription settings for PowerShell.

Import-AzurePublishSettingsFile "C:\myAzure.publishsettings"

Now you are ready to add the Endpoints in batch mode.
You need to replace the "CloudServiceName" with the name you used in the "Cloud Services" of your Azure account.  Then you need to replace the "VMName" with the name you used in the "Virtual Machines".

You can modify the code to specify your port ranges and the TCP or UDP endpoints.


$vm = Get-AzureVM -ServiceName "CloudServiceName" -Name "VMName";

$i=23401
do
{ 
 $vm |
 Add-AzureEndpoint -LocalPort $i -PublicPort $i -Name iPerfU$i -Protocol TCP | 
 Update-AzureVM; 
 $i+=1
}
until ($i -gt 23409 )

 

No comments: