Canarys | IT Services

Blogs

Create a Windows Server 2012 R2 VM using ARM in Azure PowerShell

Date:
Author:
Share

Hi Folks,

In this Blog Post we will learn how to create an Azure ARM Virtual Machine using Azure PowerShell.

For this, you will need an Azure Subscription and machine with Latest Azure PowerShell installed.

 

1.

Run the following script in Azure Powershell:  //Replace MyName with YourName everywhere.

Login-AzureRmAccount

 

$locName = "Central US"

$rgName = "MyName-RG"

$vnetName = "MyName-VNET"

 

#Getting the Storage Account

$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $rgName

$StorageName = $StorageAccount.StorageAccountName

 

#Getting the Virtual Network MyName-VNET

$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName

 

#Create a Public IP address

$ipname = "MyNameVM2-PIP"

$pip = New-AzureRmPublicIpAddress -Name $ipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic

 

# Create A Network Interface

$nicName = "mynamevm2nic"

$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id

 

#Get Credentails

$cred = Get-Credential -Message "Type the name and password of the local administrator account."

 

#Choose a VM name and Size

$vmName = "MyNameVM2"

$vm = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_A1"

 

$compName = "MyNameVM2"

$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $compName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate

 

$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"

 

$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

 

$blobPath = "vhds/MyNameVM2osDisk.vhd"

$osDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + $blobPath

 

$diskName = "windowsvmosdisk"

$vm = Set-AzureRmVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage

 

New-AzureRmVM –ResourceGroupName $rgName -Location $locName -VM $vm

 

2.

When prompted, enter your Azure Credentials.

VM1

 

3.

Enter MyName as the Username and  as password.

VM2

 

4.

Wait for a couple of minutes for the VM to be configured.

VM3

 

5.

To connect to your VM, Navigate to Azure portal. Click on Browse -> Virtual Machines

VM4

 

6.

Click on the VM named MyNameVM2 then click on connect. 

VM5

 

7.

Double Click the downloaded RDP file and then click on Connect.

VM6

8.

 

Click on Use another account.

VM7

 

9.

Enter MyNameVM2MyName as username and  as password.

VM8

 

10.

Click Yes.

 

VM9

 

11.

Confirm your connection inside VM.

VM10

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Reach Us

With Canarys,
Let’s Plan. Grow. Strive. Succeed.