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. https://msandbu.wordpress.com/2013/01/09/managing-windows-azure-via-windows-powershell/
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 à
http://msdn.microsoft.com/en-us/library/windowsazure/jj152841.aspx

I also recommend that you take a look at Michael Washam’s blog à
http://michaelwasham.com/

Get Datacenter Location
Get-AzureLocation

Shows what kind of Locations and what services it has available.
End
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 msandbutest2222222.cloudapp.net 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
GetAzureVM ServiceName konge
Name “msandbu222222” | AddAzureEndpoint Name “HttpIn”
Protocol “tcp”
PublicPort 80 LocalPort 8080 | UpdateAzureVM

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 (10.4.3.1)

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

# 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…..

Leave a Reply

Scroll to Top