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
This SOP shows how to Create a Windows VM in Azure Account. Please read thoroughly before executing the steps.
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.
Note: Name of VM cannot end with special characters.
Name can contain minimum 1 and maximum 64 character.
Note: Password must have 3 of the following (1 Lower- and Upper-case character,1 Number and 1 Special character)
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 4
# 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
# 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 4
# 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
SOP no. | Effective | Significant Changes | Previous |