Wednesday, January 28, 2015

Create a virtual machine on Microsoft Azure by PowerShell

To create a virtual machine on Microsoft Azure by PowerShell, we need to download and install Microsoft Azure PowerShell from "Web Platform Installer 5.0". The downloaded package from the Microsoft Azure web page. It automatically selected the required components for installation in Web Platform Installer 5.0.



After installing the package, Microsoft Azure PowerShell can be found on start menu.

Prerequisites
  • One storage account has been created on your Microsoft Azure subscription

Goal

  • Create a virtual machine on Microsoft Azure by PowerShell
1. Launch "Microsoft Azure PowerShell".


2. Then, we need to add the Microsoft Azure account by performing "Add-AzureAccount".
3. The "Sign in to Windows Azure" window popped up automatically.



4. Enter your Azure credential, click "Continue".
5. On "Sign in" page, enter the user name and password of your Microsoft Azure subscription, then click "Sign in".




Now, we connected to my Microsoft Azure account.

6. By default, the Microsoft Azure subscription hasn't been mapped to any storage account. We can perform Get-AzureSubscription to verify CurrentStorageAccountName and SubscriptionName.



7. Then, perform Get-AzureStorageAccount  to verify the storage account name.



8. Map the storage account to the Microsoft Azure subscription by performing Set-AzureSubscription -SubscriptionName 'Free Trial' -CurrentStorageAccountName vmlabstore01.



Before create a new virtual machine, we need to check the image name and instance size by performing Get-AzureVMImage and New-AzureVMConfig.

9. Perform Get-AzureVMImage | ogv to show all images on Microsoft Azure in a window.



Some images like SQL are provided "RecommendedVMSize" for information.

10. Perform help New-AzureVMConfig -Parameter InstanceSize to check the instance size values.



Remark: The string of InstanceSize is case-sensitive.

Assuming that we'd like to create a new virtual machine from Windows Server Technical Preview image.

11. Perform $pwd = Read-Host "Password" and then enter a password to store in a variable.



12. Perform New-AzureVMConfig -Name labmachinevm01 -InstanceSize Small -ImageName (Get-AzureVMImage | Where ImageFamily -match 'Technical Preview').ImageName | Add-AzureProvisioningConfig -Windows -AdminUsername LabAdmin -Password $pwd | New-AzureVM -ServiceName labmachinevm01 -Location 'East Asia' to create a new virtual machine named labmachinevm01 in Microsoft Azure.



The virtual machine, labmachinevm01, is being created.

Then, we can perform Get-AzureVM to check the status of virtual machines.


As a result, virtual machine has been created on Microsoft Azure by performing PowerShell.

More information
New-AzureVM

New-AzureVMConfig

Add-AzureProvisioningConfig

Get-AzureVMImage

This posting is provided “AS IS” with no warranties, and confers no rights!

No comments:

Post a Comment