Creating Windows VM in Azure

Creating Windows VM in Azure


SOP No: AZ-002

SOP Title: Create a Windows VM in Azure Account  


Review Date: Insert Date



SOP Number 

AZ002 

 

SOP Title 

Create a Windows VM in Azure Account  

 

  

NAME 

TITLE 

SIGNATURE 

DATE 

Author 

Shivam Singh 

Cloud Engineer 

  

  

First Reviewer  

Varun Kumar 

Product Manager Trainee 

  

  

Second Reviewer  

  

  

  

  

Authoriser 

Henry/Aditya 

CTO 

  

  

  

  

  

Effective Date: 

  

  

Effective Time: 

  .5

 

Other Essential SOPs 

 

  • NONE 

 

  1.  PURPOSE 

This SOP shows how to Create a Windows VM in Azure Account. Please read thoroughly before executing the steps. 

 

  1. Basic Requirement   
  • PowerShell with Az module Installed. 
  • Valid Credential to login to the account. 

      Note: All the lines starting with # in script are comments for better understanding. 

Note: You can find the complete PowerShell Commands file at the End of the Document. 

 

 

 

 

  1. Pre- Requisite 
  • Resource Group Name 
  • Virtual network name and CIDR 
  • Subnet CIDR 
  • Name of VM 

         Note: Name of VM cannot end with special characters. 

                    Name can contain minimum 1 and maximum 64 character. 

  • Username and Password to set for Machine  

     Note: Password must have 3 of the following (1 Lower- and Upper-case character,1 Number and 1 Special character) 

  • Server: Windows or Linux 
  • Sku: VM Image  

 

  1. How to Crete a VM 
  • Run PowerShell or PowerShell ISE in Administrator mode (Preferred) 

 

 

 

 

  • Once in please change the parameter as per requirement (Below are the parameter required) 
  • Resource Group 
  • Location 
  • VM-Name 
  • V-net and Sub-net Address Prefix 

 

  • Note: Before configuring do check you are into right account for provisioning of VM with help of below command in PowerShell. 

   Get-AzContext 

 

#Step 1: Define the parameters  

 

# Variables for common values 

$Resource_Group = Read-Host -Prompt "Enter Resource Group Name" 

 

 

 

$Location = Read-Host -Prompt "Enter Location for Deployment" 

 

 

 

$VM_Name = Read-Host -Prompt "Enter Name for VM" 

 

 

$Virtual_Network_Name=Read-Host -Prompt "Enter Name For V-Net" 

 



 

 

$Subnet_Name= Read-Host -Prompt "Enter Name For SUBNET" 

 

 

 

 

$Skus= Read-Host -Prompt "Enter Image of VM" 

 

 

 

 

Step 2: Select the Size of VM  

 

 

$VM_Size= Get-AzVMSize -Location $Location | Out-GridView -PassThru 

 

 

 

 

 

#Create user object (Username and Password for the VM) 

 

$cred = Get-Credential -Message "Enter a username and password for the virtual  

machine." 

 

 

 

 

 

 

 

 

# Create a resource group 

 

New-AzResourceGroup -Name $Resource_Group -Location $Location 

 

 

# Create a subnet configuration (Do check the CIDR/ AddressPrefix ) 

 

$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name $Subnet_Name -AddressPrefix 192.168.1.0/24 

 

 

# Create a virtual network (Do check the CIDR/ AddressPrefix ) 

 

$vnet = New-AzVirtualNetwork -ResourceGroupName $Resource_Group -Location $Location

 -Name $Virtual_Network_Name -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig 

 

 

# Create a public IP address and specify a DNS name 

 

$pip = New-AzPublicIpAddress -ResourceGroupName $Resource_Group -Location $Location

 -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 

 

 

# Create an inbound network security group rule for port 3389 

 

$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleRDP  -Protocol Tcp

 -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix *

 -DestinationPortRange 3389 -Access Allow 

 

 

# Create a network security group 

 

$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $Resource_Group -Location $Location

 -Name myNetworkSecurityGroup -SecurityRules $nsgRuleRDP 

 

 

# Create a virtual network card and associate with public IP address and NSG 

 

$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $Resource_Group -Location $Location

 -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id 

 

 

# Create a virtual machine configuration 

 

$vmConfig = New-AzVMConfig -VMName $VM_Name -VMSize $VM_Size.Name |

Set-AzVMOperatingSystem -Windows -ComputerName $VM_Name -Credential $cred |

Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus $Skus -Version latest |

Add-AzVMNetworkInterface -Id $nic.Id 

 

 

# Create a virtual machine 

 

New-AzVM -ResourceGroupName $Resource_Group -Location $Location -VM $vmConfig  

 

 

 

#Script in Process of execution  

 

 

 

 

 

# If Deployment succeeds without Error you see the below screen 

 

 

 

 

 

 

  • Complete Script is as follows: 

 

  • Note: Do change the CIDR if you want to have any specific CIDR for Virtual-Network and Subnet (in the below section)  
  • # Create a virtual network (Do check the CIDR/ AddressPrefix), # Create a subnet configuration (Do check the CIDR/ AddressPrefix)   

 

 

# Variables for common values 

$Resource_Group = Read-Host -Prompt "Enter Resource Group Name" 

$Location = Read-Host -Prompt "Enter Location For Deployment" 

$VM_Name = Read-Host -Prompt "Enter Name For VM" 

$Virtual_Network_Name=Read-Host -Prompt "Enter Name For V-Net" 

$Subnet_Name= Read-Host -Prompt "Enter Name For SUBNET" 

$Skus= Read-Host -Prompt "Enter Image of VM" 

$VM_Size= Get-AzVMSize -Location $Location | Out-GridView -PassThru 

 

# Create user object (User name and Password for the VM) 

$cred = Get-Credential -Message "Enter a username and password for the virtual machine." 

 

# Create a resource group 

New-AzResourceGroup -Name $Resource_Group -Location $Location 

 

# Create a subnet configuration (Do check the CIDR/ AddressPrefix) 

$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name $Subnet_Name -AddressPrefix 192.168.1.0/24 

 

# Create a virtual network (Do check the CIDR/ AddressPrefix ) 

$vnet = New-AzVirtualNetwork -ResourceGroupName $Resource_Group -Location $Location

 -Name $Virtual_Network_Name -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig 

 

# Create a public IP address and specify a DNS name 

$pip = New-AzPublicIpAddress -ResourceGroupName $Resource_Group -Location $Location

 -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 

 

# Create an inbound network security group rule for port 3389 

$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleRDP  -Protocol Tcp

 -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix *

 -DestinationPortRange 3389 -Access Allow 

 

# Create a network security group 

$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $Resource_Group -Location $Location

 -Name myNetworkSecurityGroup -SecurityRules $nsgRuleRDP 

 

# Create a virtual network card and associate with public IP address and NSG 

$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $Resource_Group -Location $Location

 -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id 

 

 

 

# Create a virtual machine configuration 

$vmConfig = New-AzVMConfig -VMName $VM_Name -VMSize $VM_Size.Name |

Set-AzVMOperatingSystem -Windows -ComputerName $VM_Name -Credential $cred |

Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus $Skus -Version latest |

Add-AzVMNetworkInterface -Id $nic.Id 

 

# Create a virtual machine 

New-AzVM -ResourceGroupName $Resource_Group -Location $Location -VM $vmConfig 

 

 

 

 

  

  1.  Change History


SOP no.

Effective
Date

Significant Changes

Previous
SOP no.



















 

 

 

 

 




    • Related Articles

    • What is Azure Load Balancer?

      Load balancing refers to efficiently distributing load or incoming network traffic across a group of backend resources or servers. Azure offers a variety of load balancing options that you can choose from based on your need. This document covers the ...
    • SOP for Whitelist IP on Azure

      SOP No: AZ-003 SOP Title: Whitelisting IP on Azure Review Date: Insert Date SOP Number AZ003 SOP Title Whitelisting IP on Azure NAME TITLE SIGNATURE DATE Author Ankit Jain Cloud Engineer First Reviewer  Varun Kumar Product Manager Trainee Second ...
    • Login-To-Azure

      SOP No: AZ-001 SOP Title: Log in to Azure Account  Review Date: Insert Date SOP Number AZ001 SOP Title Log in to Azure Account   NAME TITLE SIGNATURE DATE Author Shivam Singh Cloud Engineer First Reviewer  Varun Kumar Product Manager Trainee Second ...
    • Windows Servers Security Patches Activity[1033]

      SOP No: WIN-001 SOP Title: Window Servers Security Patches Activity Review Date: Insert Date SOP Number WIN001 SOP Title  Windows Servers Security Patches Activity   NAME TITLE SIGNATURE DATE Author Ankit Jain Cloud Engineer First Reviewer  Varun ...
    • Schedule Start-Stop VMs SOP[1061]

      SOP No: AZ-004 SOP Title: Schedule VM start and Stop Review Date: Insert Date SOP Number AZ004 SOP Title  Schedule VM start and Stop   NAME TITLE SIGNATURE DATE Author Ankit Jain Cloud Engineer First Reviewer  Varun Kumar Product Manager Trainee ...