Windows Azure – Create Service using PowerShell

Windows Azure PowerShell has set of cmdlets which can be used to create a new windows azure service.

Before starting there are couple of pre-requisite to run below script-

To make sure  you can run remote signed scripts in PowerShell you need to run following command on powershell command prompt-

Set-ExecutionPolicy RemoteSigned

I am assuming you must have installed windows azure powershell cmdlets. if not please install the Windows Azure Cmdlets (http://www.windowsazure.com/en-us/manage/downloads/).

Now you need to import the cmdlets by using following command-
Import-Module “C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1

Following is the set of cmdlets which can be combined and used in step wise manner to create new azure service:-

Before creating any service on windows azure, one need to connect to windows azure subscription. There are multiple ways to connect to the subscription. One way is to connect using publish file. Publish file can be downloaded from Azure portal.  I will probably discuss that approach in some other post. Right now I am going to explain the other approach where you will require

  • Subscription-Id -This can be found from Windows Azure portal
  • Subscription Name- Name of the azure subscription
  • Certificate Thumbnail – This is required to create a trusted connection to remote windows azure subscription. Required certificate should be uploaded to windows azure subscription’s certificate store.

For above information you can create powershell variables and use it though out the script.
Following script can be run to connect the azure subscription –

# Variable Declaration
$subid = ‘SUBSCRIPTION-ID. THIS CAN BE FOUND ON AZURE PORTAL’
$subsName=’NAME OF THE SUBSCRIPTION. THIS CAN BE FOUND FROM AZURE PORTAL’
$cert = Get-Item Cert:\CurrentUser\My\THUMBNAIL OF CERTIFICATE
$serviceName = ‘PUT THE NAME OF THE SERVICE TO BE CREATED’
$ServiceLabel = ‘LABEL FOR THE NEW SERVICE’
$Affinitygroup = ‘LOCATION WHERE NEW SERVICE WILL BE DEPLOYED. E.G., WEST US’

#Set the subscription
Set-AzureSubscription -SubscriptionName $subsName -SubscriptionId $subid -Certificate $cert

Once you are connected, you can get the details of subscription detail by following cmdlet –

Get-AzureSubscription

Now to create new service within the subscription following cmdlets can be used-

New-AzureService -ServiceName $serviceName -Label “MyTestService” -Location $Affinitygroup

Once you run the above command the new service will be created on the subscription.

I will be discussing another approach to connect to windows azure subscription and deploy service using package file and configuration file.