View Single Post
  #8  
Old 04-30-2014, 09:35 AM
daerath
Sarnak
 
Join Date: Jan 2011
Location: Northern VA
Posts: 91
Default

How to install and configure Windows Azure Powershell
http://azure.microsoft.com/en-us/doc...re-powershell/

1. On your VM navigate to: http://go.microsoft.com/fwlink/p/?li...76&clcid=0x409
2. Run the file you are prompted to download. At this moment it will open the Web Platform Installer 4.6.
3. Click Install.
4. Click I Accept.
5. Wait for it to finish. Time varies based on your chosen VM size. An A1 (1 core, 1.75 GB RAM) will take a bit. On my A3 (4 cores, 7GB RAM) it went pretty quickly.
6. Click Finish.
7. Click Exit.

Get your Publish Settings file (there is also an option to use Azure AD, but I didn’t)
1. Open a Powershell window.
2. run the following command “Get-AzurePublishSettingsFile” (without quotes)
3. You will be prompted to log into your Azure Subscription. When you’ve logged in, you will be taken to a page where your subscription file is generated. Download it somewhere (I chose desktop).

For the next steps I am assuming that you named your subscription file “azuresubscriptioncredentials.publishsettings”. You can name it whatever you want, but you’ll have to put in the correct filename.

Import your Publish Settings file
1. In the same Powershell window (or a new one if you closed it), run the following command “Import-AzurePublishSettingsFile azuresubscriptioncredentials.publishsettings” (without quotes)
2. To verify installation, run the following command “Get-AzureSubscription” and you should see a page of details including your Certificate and Subscription ID.

Now, run the script. It will take a while, so don’t be impatient. =)

Code:
# Import the necessary powershell module
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"

function CreateEndPoint($portNumber, $endpointPrefix, $serverName)
{
  Write-Host 'Creating Azure Endpoint:' $endpointPrefix$portNumber
  Get-AzureVM -ServiceName $servername -Name $servername | Add-AzureEndpoint -LocalPort $portNumber -PublicPort $portNumber -Name $endpointNamePrefix+$portNumber -Protocol UDP | Update-AzureVM;
}

# Get your subscription
$sub = Get-AzureSubscription

# Set the subscription.  If you don't do this, you can't run any of the Azure Powershell scripts.
Set-AzureSubscription -SubscriptionName $sub.SubscriptionName -SubscriptionId $sub.SubscriptionId -Certificate $sub.Certificate

# Your server's name.
$servername = $env:COMPUTERNAME

# The endpoint prefix to help us identify why the endpoint exists
$endpointNamePrefix = "Emu"

# Singles
$singlePorts = @(5998,5999,9000)

foreach ($port in $singlePorts)
{
  CreateEndPoint $port $endpointNamePrefix $servername
}

# Create the 7000 - 7100 range
for ($i = 7000; $i -le 7100; $i++)
{
  CreateEndPoint $i $endpointNamePrefix $servername
}
Reply With Quote