Showing posts with label Microsoft Azure. Show all posts
Showing posts with label Microsoft Azure. Show all posts

How to find the latest OS Image from Microsoft Azure Galery

This post is for reference and is intended to simplify the way of finding the latest available operating system image from Azure gallery using PowerShell (I will not get into details how to connect to your azure subscription using PowerShell).
Here is an example of how to get the latest image for Windows Server 2012 R2 Datacenter edition:

$OSImage = (Get-AzureVMImage | where {$_.ImageFamily -like "Windows Server 2012 R2 Datacenter*"} | sort PublishedDate -Descending)[0].ImageName

or Ubuntu Server 14 LTS:

$OSImage = (Get-AzureVMImage | where {$_.ImageFamily -like "Ubuntu Server 14*LTS*"} | sort PublishedDate -Descending)[0].ImageName


The logic in these one liners PowerShell is very simple, the output from Get-AzureVMImage is first filtered by ImageFamily and then sorted descending by PublishedDate. The first listed (latest published) image name is put into $osimage variable. Now, "armed" with latest image of the operating system, you can proceed in creating Azure Virtual Machine.
 

Free Exam Vouchers

If you're MCT, checkout the latest promotion from Microsoft Learning on http://borntolearn.mslearn.net/goodstuff/p/mctchallenge.aspx . Free Exam Vouchers Offer is valid until 30.11.2014 up to 10000 vouchers distributed worldwide, and a voucher may be redeemed to take any MCP Exam !!!
For the best MCTs there are special prizes like Surface Pro 3 and XBOX One !

Also, If you want to become an MCP checkout the latest promotion from Microsoft Learning on http://borntolearn.mslearn.net/goodstuff/p/mcp.aspx . There is free exam vouchers offer for Azure Exams and Office 365 Exams. The offer is valid until 31.12.2014 up to 10000 vouchers distributed worldwide.

Don't miss the offers !
 

How to move Azure VM to different Cloud Service

In this case I wanted to move Azure VM from one cloud service to another cloud service in same Azure Subscription. Using Microsoft Azure Web Portal this task can be achieved in following three steps:
  • Note the disk(s) that were attached on Azure VM, and other configuration settings like VM size, virtual network, endpoints and so on.
  • Delete the Azure VM with option to keep the attached disks
  • Create new VM from Gallery, and on first Wizard page (Chose an Image) select MY DISKS option, and select the disk noted in first step. Complete the wizard with assigning the VM to the new Cloud Service.
In my case the VM was having couple of additional data disk drives, and I was unable to attached them using Azure Web Portal Create New Virtual Machine from Gallery Wizard. But, this can be easily achieved using Powershell. The script is very easy to read, and is consisted of:
  • Setting the currentStorageAccount for the Azure Subscription
  • Setting basic variables for the VM, like Name, disks, virtual network, subnet and cloud service
  • Creating new configuration for the VM
  • And, finally creating the new VM

Set-AzureSubscription -SubscriptionName 'Name of the subscription' -CurrentStorageAccount 'teststorageaccount'

$vmName='test'
$disk0Name = 'test-os-disk0'
$disk1Name = 'test-data-disk-1'
$disk2Name = 'test-data-disk-2'
$vNetName = 'test-VirtualNetwork'
$subNet = 'Sub-1'
$cloudSvcName = 'test-Cloud-Service2'


$vm1 = New-AzureVMConfig -DiskName $disk0Name -InstanceSize Medium -Name $vmName -Label $vmName |
Add-AzureDataDisk -DiskName $disk1Name -Import -LUN 0 |
Add-AzureDataDisk -DiskName $disk2Name -Import -LUN 1 |
Set-AzureSubnet $subNet |
Add-AzureEndpoint -LocalPort 3389 -Name 'RDP' -Protocol tcp -PublicPort 3390 |
Add-AzureEndpoint -LocalPort 5986 -Name 'WinRmHTTPs' -Protocol tcp -PublicPort 5987 |
Add-AzureEndpoint -LocalPort 80 -Name 'http' -Protocol tcp -PublicPort 80 |
Add-AzureEndpoint -LocalPort 443 -Name 'https' -Protocol tcp -PublicPort 443


New-AzureVM -ServiceName $cloudSvcName -VMs $vm1 -VNetName $vNetName

In bold are the two additional data disk, that will be attached during creation of the VM in the new cloud service.
 

How to create predictible (static) ip address for Azure VMs

In Microsoft Azure all created VMs have internal IP addresses assigned from DHCP server, and those IP addresses are within the defined virtual network scope if you have created virtual network. The IP address assigned by the DHCP to the Azure VM, will remain the same for the vm's lifetime as long as the VM is not in Stop (Deallocated) state. Here is output from the ipconfig /all from the Azure VM:


This means that when the VM is shut down from the operating system (you're paying for the VM in this state), it will obtain the same IP (in this example 10.0.0.5) when the VM will start up again. Also, while this VM is in Stopped state (shut down from the OS), no other VM will be offered the same 10.0.0.5 address. And here is the state of the VM from Azure Portal:


In case when you don't want to pay for the VM, you have to shut down the VM from the Azure portal or Powershell, and the VM will be in Stopped (Deallocated) state :


Starting the VM from this (Stopped -Deallocated) state, the VM will start the new provisioning process and there is a chance to obtain some other IP address. So, here is a question: Is there a way to define some preferred address for the VM, when the VM is starting from Stopped (Deallocated) state ?
And, the answer is fortunately Yes. There is Set-AzureStaticVNetIP cmdlet which can set preferred IP address for the VM when starting from Stopped (Deallocated) state. For example the syntax for assigning the static (preferred) IP address for previously created Azure VM is:

Get-AzureVM -ServiceName testService -Name test | Set-AzureStaticVNetIP -IPAddress 10.0.0.5 | Update-AzureVM

Note that running this command will trigger reboot of the VM. Related cmdlets for checking, testing and removing the assigned static IP addresses from the Azure VMs are also available ( Get-AzureStaticVNetIP, Test-AzureStaticVNetIP, Remove-AzureStaticVNetIP )

It's important to understand that, this static IP address assigned with Set-AzureStaticVNetIP will NOT create reservation of the IP address for that VM. Instead, it will create preferred IP address for the VM when starting from Stopped (Deallocated) state, which means that that IP address might be already taken by other virtual machine, while the VM with static assigned IP was in Stopped (deallocated) state !
 

How to check EMBG (Unique Master Citizen Number) using regex

In this post, I will share my implementation of how to check if some number looks like EMBG or Unique Master Citizen Number. For those of yo...