Azure and PowerShell

Been working into Azure and using PowerShell the last couple of weeks, so therefore I thought that I would share some of my scripts that found in handy.
First of you need to make sure you have installed Azure Powershell cmdlets and connected to your account.
You can read my previous post to get started, but some scripts I’ll make post later in the post.
But also make sure that you visit the documentation on Microsoft site à

I also recommend that you take a look at Michael Washam’s blog à

Get Datacenter Location

Shows what kind of Locations and what services it has available.
List out Image names available from Quick Wizard
Get-AzureVMImage | ft Imagename

Create Quick VM (Before you do this you need to select a storage account Get-AzureStorageAccount | Select StorageAccountName ) or Set-AzureStorageAccount -StorageAccountName
New-AzureQuickVM -Windows
-ServiceName konge -Name msandbutest2222222 -ImageName fb83b3509582419d99629ce476bcb5c8__Microsoft-SQL-Server-2012SP1-Web-CY13SU04-SQL11-SP1-CU3-11.0.3350.0 -Location «West Europe» -Password SupermanUpandAtom.
This will create a VM with with the service name of Konge and the vm name of and use the default image for SQL server 2012 and located in West Europe and with the password of SupermanUpandAtom.

Add Endpoint to a VM
Get-AzureVM -ServiceName konge
-Name «msandbu222222″ | Add-AzureEndpoint -Name «HttpIn»
-Protocol «tcp»
-PublicPort 80 -LocalPort 8080 | Update-AzureVM

VM Batch Creation
(First we have to define a config for a VM and create a VM there or we can create a batch)

New-AzureVMConfig -Name $vm1 -InstanceSize Medium -ImageName $img |
Add-AzureProvisioningConfig -Windows
-Password $pwd |
Add-AzureDataDisk -CreateNew
-DiskLabel ‘data’ -DiskSizeInGB 10 -LUN 0 |
Add-AzureEndpoint -Name ‘web’ -PublicPort 80 -LocalPort 80 -Protocol tcp |

New-AzureVM -ServiceName $newSvc -Location $location (Now we could either use all the config here and create a new VM or we could define multiple varibles for batch provisioning with a defined instancesize.

$vm1 = New-AzureVMConfig -Name ‘myvm1′ -InstanceSize ‘Small’ -ImageName $img | Add-AzureProvisioningConfig -Windows
-Password $pwd
$vm2 = New-AzureVMConfig -Name ‘myvm1′ -InstanceSize ‘Small’ -ImageName $img | Add-AzureProvisioningConfig -Windows
-Password $pwd
$vm3 = New-AzureVMConfig -Name ‘myvm1′ -InstanceSize ‘Small’ -ImageName $img | Add-AzureProvisioningConfig -Windows
-Password $pwd

New-AzureVM -CreateService
-ServiceName $cloudSvcName -VMs $vm1,$vm2,$vm3 -Location $dc.

Or we can use an array to create multiple VMs;

$vmcount = 5
$vms = @()
for($i = 0; $i -lt 5; $i++)


$vmn = ‘myvm’ + $i
$vms += New-AzureVMConfig -Name $vmn -InstanceSize ‘Small’ -ImageName $img |
Add-AzureProvisioningConfig -Windows
-Password $pwd |
Add-AzureDataDisk -CreateNew
-DiskLabel ‘data’ -DiskSizeInGB 10 -LUN 0 |
Add-AzureDataDisk -CreateNew
-DiskLabel ‘logs’ -DiskSizeInGB 10 -LUN 1


New-AzureVM -ServiceName $cloudSvcName -VMs $vms -Location $dc.

VM Provisioning config setup
New-AzureVMConfig -Name "MyDomainVM" -InstanceSize Small -ImageName $img ` | Add-AzureProvisioningConfig -WindowsDomain –Password $Password -ResetPasswordOnFirstLogon -JoinDomain "test.local" -Domain "test" -DomainUserName "domainadminuser" -DomainPassword "domainPassword" -MachineObjectOU 'OU=AzureVMs,DC=test,DC=no' | New-AzureVM -ServiceName $svcName

(Note that the domain part here requires that a DNS server can fully locate the domain controller)

or we can also define DNS server settings

Deploy a new VM and join it to the domain

#Specify DC's DNS IP (

$myDNS = New-AzureDNS -Name 'testDC13' -IPAddress ''

# Operating System Image to Use

$image = 'MSFT__Sql-Server-11EVAL-11.0.2215.0-08022012-en-us-30GB.vhd'

$service = 'myazuresvcindomainM1'

$AG = 'YourAffinityGroup'

$vnet = 'YourVirtualNetwork'

$pwd = 'p@$$w0rd'

$size = 'Small'

#VM Configuration

$vmname = 'MyTestVM1'

$MyVM1 = New-AzureVMConfig -name $vmname -InstanceSize $size -ImageName $image | Add-AzureProvisioningConfig -WindowsDomain -Password $pwd -Domain 'corp' -DomainPassword 'p@$$w0rd' -DomainUserName 'Administrator' -JoinDomain 'test.local '| Set-AzureSubnet -SubnetNames 'SubnetName'

New-AzureVM -ServiceName $service -AffinityGroup $AG -VMs $MyVM1 -DnsSettings $myDNS -VNetName $vnet

Add new Data Disk to existing Virtual Machine (Make note that a datadisk has a 1 TB max limit)

Get-AzureVM -ServiceName 'myvm1' |   Add-AzureDataDisk -CreateNew
					-DiskSizeInGB 10  -DiskLabel 'myddisk' -LUN 1 |   Update-AzureVM 

Get RDP file for VM
Get-AzureRemoteDesktopFile -ServiceName "myservice"
											-Name "MyVM-01_IN_0" –Launch 

To be updated…..
About these ads

Posted on mai 13, 2013, in Uncategorized. Bookmark the permalink. Legg igjen en kommentar.

Legg igjen en kommentar

Fyll inn i feltene under, eller klikk på et ikon for å logge inn:

Du kommenterer med bruk av din konto. Logg ut / Endre )

Twitter picture

Du kommenterer med bruk av din Twitter konto. Logg ut / Endre )


Du kommenterer med bruk av din Facebook konto. Logg ut / Endre )

Google+ photo

Du kommenterer med bruk av din Google+ konto. Logg ut / Endre )

Kobler til %s

Følg meg

Få nye innlegg levert til din innboks.

Bli med 59 andre følgere

%d bloggers like this: