Sunday, 22 March 2015

Creating VM through PowerShell Part I (Quick Create)

There are many ways to create VM in Microsoft Azure as listed below:

  1. Azure Management Portal
  2. Azure PowerShell
  3. Azure cross-platform command line tools like xplat-cli
  4. Management REST-API

I have already made separate article for VM creating through Azure Management Portal, which you can refer to http://squons.blogspot.in/2015/03/creating-virtual-machine-in-microsoft.html.

In this article, we will see how to create Virtual Machine through Azure PowerShell.

But what do you mean by Azure PowerShell.

To understand this, let’s first understand what Microsoft Windows PowerShell is.

Windows PowerShell is a .NET framework which help us to automate and manage configuration through command line shell or scripting language.

Likewise, we have Azure PowerShell which is powerful scripting tool used to automate, control, deploy and manage your workloads in Microsoft Azure.

To install and configure Azure PowerShell, go to http://azure.microsoft.com/en-in/documentation/articles/powershell-install-configure/.

In this article, we will be seeing how to create Virtual Machine through Azure PowerShell.

Following are the syntax to be used to deploy “Quick Create” VM in Microsoft Azure through Azure PowerShell:

$adminUser = "Username"
$password = "Password"
$serviceName = "Service_Name"     # ServiceName means CloudService name e.g. “squons”
$location = "Location_Name"    # In which location you want to deploy your VM e.g. "West US"
$size = "Size_Name"                    # Size/Tier name e.g. “Small/Medium/Large” etc
$vmName = "VM_Name"   # Name or Virtual Machine e.g. “SQUONS-VM1”
$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage |
                                                            where { $_.ImageFamily -eq $imageFamily } |
                                                            sort PublishedDate -Descending |
                                                            select -ExpandProperty ImageName -First 1
New-AzureQuickVM -Windows `
                                    -ServiceName $serviceName `
                                    -Name $vmName `
                                    -ImageName $imageName `
                                    -AdminUsername $adminUser `
                                    -Password $password `
                                    -Location $location `
                                    -InstanceSize $size


Following figure depicts the PowerShell command used to deploy VM in Microsoft Azure:



To check the VM status through Azure PowerShell, use the below command:

PS C:\> Get-AzureVM


Here it ends with the article.

Below I have mentioned about an error which I encountered while deploying VM through Azure PowerShell.



To overcome this error, I used the following command:


Syntax:

PS C:\> Set-AzureSubscription –SubscriptionName "Sub_Name" -CurrentStorageAccount "Storage_Name"

To see how to "Custom Create" VM through PowerShell, go to http://squons.blogspot.in/2015/03/creating-vm-through-powershell-part-ii.html.


No comments:

Post a Comment