Azure Windows Virtual Machine (VM)
Azure Windows Virtual Machines (VMs) are one of several types of on-demand, high-scale, secure computing resources that Azure offers, gives more control over the computing environment. An Azure VM gives you the flexibility of virtualization without having to acquire and maintain the physical infrastructure that runs it.
Certainly, Azure virtual machines (VMs) enable you to create dedicated compute resources in minutes that can be used just like a physical desktop or server machine. Azure VMs can be used in a numerous ways, like –
- Use as per looked-for, the development or staging environment.
- Manage the variation of applications be located in in the cloud.
- Work as extended datacenter connected with on-premises through VNET.
Before moving to creating a Windows VM, it is essentials to consider a few aspects Like –
- Name of Azure Windows VM.
- Region or location where VM will be stored.
- Image of the operating system (Here Windows Server).
- Size and configuration (CPU, Memory etc.) details.
- Other related bits and pieces such as disk, network, IP and monitoring etc.
Azure PowerShell
We can use the Azure PowerShell module to create and manage Azure resources from the PowerShell command line or in scripts. Basically Azure PowerShell is an extended version of Windows PowerShell platform and scripting language to deliver cmdlets to accomplish a robust task in the context of Azure cloud services.
Cmdlets (pronounced as "command-let”) are lightweight preset scripts or commands through which an Azure PowerShell programmer can perform various tasks like provisioning VMs, automate jobs, backup and restore, etc. in the Microsoft PowerShell environment.
If bit more details require, visit my precise post about the Azure PowerShell introduction and its installation as well some hands-on activity.
Pre-requisites
Couple of essential pre-requisites are needed to provision a Windows VM on top of Azure Cloud using Azure PowerShell.
- Azure PowerShell
- Azure subscription, if you don't have an account then sign up for a free Azure account - https://azure.microsoft.com/en-gb/free/
STEP – 1: Connect to Azure account
I trust you already installed the Azure PowerShell with required version using Windows PowerShell, but still not ready, then you can visit the previous post about the Azure PowerShell installation.
Execute the following command to connect with Azure, it will open an interactive dialog for Sign-in, sign in with your Azure credentials subsequently.
Connect-AzureRmAccount
Post submission of credentials and successful connection, it will be linked and display your account details such as –
STEP – 2: Create Resource Group
A Resource group is a logical container where you can deploy and manage Azure Stack resources under one umbrella. Execute the following command to validate if any Resource group exists or not in your subscription.
Get-AzureRmResourceGroup
It looks like one Resource group named as ‘raj-resources’ already exist, which located to ‘eastus’ Location. Now I can either opt this existing Resource group or can go to create a new one.
I am considering a new Resource group underneath the Windows VM will be created. Execute the following command to create a new Resource group with specified location.
New-AzureRmResourceGroup -Name 'demoResourceGroup' -Location 'eastus2'
You can validate the newly created Resource group name and Location simultaneously, execute the following command.
Get-AzureRmResourceGroup | Select-Object ResourceGroupName,Location
STEP – 3: Create common variables
Once the resource group has been created or existing one designated, next onward create a couple of variables to store some common values like –
- Name of the Resource group
- Name of Location
- Name of Windows VM
$resourceGroup = "demoResourceGroup"
$location = "eastus2"
$vmName = "windowsCloudVM"
STEP – 4: Setup credentials
Next, need to setup the credential details, execute following command to set User name as well Password.
$credential = Get-Credential –Message “Submit VM administrator User Name and Password”
The moment you execute the above command, system will launch a wizard to take User name and Password from your end. Here to submit the VM administrator’s User name and Password details.
STEP – 5: Configure the Subnet details
We know that a Subnetwork or Subnet is a logical subdivision of an IP network, execute following command to configure the subnet variable.
$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name cloudWindowsSubnet -AddressPrefix 192.168.2.0/24
STEP – 6: Setup virtual network
An Azure Virtual Network (VNET) is an interpretation of your own network in the cloud, something a logical separation of the Azure cloud dedicated to your subscription only. Execute the following command to setup the VNET variable using previously created variables.
$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location -Name windowsCloudVNet -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig
NOTE: Ignore the breaking change warning which is something minimum PowerShell version required bumped to 5.0.
STEP – 7: Setup Public IP (random)
Later on doing setup the Public IP address, a Public IP addresses allow Internet resources to communicate inbound to Azure resources as well enable Azure resources to communicate outbound to.
Execute following command to assign a variable to the random Public IP and verify the same.
$publicIp = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location -Name "windowscloudpublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4
STEP – 8: Configure ACL and NSG group
In fact, the Virtual Network (VNET) is the foundation of the Azure networking model and provides separation and protection, but the Network Security Group (NSG) is the main tool you need to use to enforce and control network traffic rules.
NSG contains a list of Access Control List (ACL) rules that allow or deny network traffic to your VM instances in a Virtual Network.
Since we will access the said Windows VM through RDP so need to configure the network contact for the port 3389 accordingly, execute the following commands to map the variable an inbound network security group rule.
$nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig -Name windowsCloudNetworkSecurityGroupRuleRDP -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow
Next, define a variable containing a network security group.
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location -Name windowsCloudNetworkSecurityGroup -SecurityRules $nsgRuleRDP
STEP – 9: Setup network interface card (NIC)
Next, configure the network interface, a network interface card (NIC) enables an Azure Virtual Machine to communicate with the internet, Azure, and on-premises resources.
Execute following command to setup a network interface and associate with previously created Public IP and NSG rule.
$nic = New-AzureRmNetworkInterface -Name windowsCloudNic -ResourceGroupName $resourceGroup -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id -NetworkSecurityGroupId $nsg.Id
STEP – 10: Setup Windows VM configuration
Now, almost all initial configuration has been done, time to configure the Windows virtual machine. This configuration includes the settings used when deploying the virtual machine. For example: user credentials, size, and the virtual machine image.
Execute the following command to configure Windows Server 2016 provided by the Microsoft.
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_D1" |
Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName -Credential $credential |
Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version latest |
Add-AzureRmVMNetworkInterface -Id $nic.Id
STEP – 11: Create the Windows VM
Finally, all setup and configuration has been done, time to create a new Windows VM based on above all defined formations. Execute the final command to create the Virtual Machine.
New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig
Creating the VM will take some time depends on configuration and size, meanwhile Ignore the warning, if system throws anything during the creation of virtual machine, post creation you will get an acknowledgement.
Congratulation, Windows VM is created!! 😊
You can verify the Virtual Machine through the Azure Portal also, login to Azure portal - https://portal.azure.com/.
On the left Hub menu, click All resources and select the newly created Windows virtual machine, seems to appear the VM Status Running.
Connect the Windows VM
It is time to connect the VM, you can login the Windows virtual machine using either mstsc utility and the public IP address or go ahead with the downloaded RDP file.
Let’s go through with both options.
[1] Using mstsc utility
Move inside to the Overview blade of virtual machine, further copy the Public IP address.
Run the mstsc utility which launches the remote desktop connection and go through submitting the copied Public IP Address to connect the server remotely.
[2] Using downloaded RDP file
Inside the Overview blade, click the Connect button from the menu bar.
Promptly, it will load the Connect to virtual machine blade, click the Download RDP File button to get the RDP connection.
You will get a Save As dialog box subsequently by clicking the button, save the connection file in your preferred place.
You can connect the server using Connect option, right click of RDP file – Connect.
Though, you can opt any one option, that will lead to connect the newly created Windows virtual machine providing the same administrator User name and password which you were supplied during the provision of VM.
Congratulation, Azure Windows VM connected!! 😊
In the short-term, here in this article, we walked through the outline of Azure VM and how to use the Azure PowerShell module to deploy an Azure Virtual Machine (VM) in Azure that runs Windows Server 2016.
Keep visiting for further posts.
This is such an incredible asset, that you are giving and you part with it for nothing. I love seeing websites that comprehend the benefit of giving a quality asset about windows. Oracle fusion financials training
ReplyDelete