Setup a Windows Virtual Machine in the Azure Cloud using Azure PowerShell

Windows VM in Azure Cloud

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

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. 


Couple of essential pre-requisites are needed to provision a Windows VM on top of Azure Cloud using Azure PowerShell.
  1. Azure PowerShell
  2. Azure subscription, if you don't have an account then sign up for a free Azure account -

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 Azure

Sign in Azure

Post submission of credentials and successful connection, it will be linked and display your account details such as –

Account Details

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.


Resource Group

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'

New Resource Group

You can validate the newly created Resource group name and Location simultaneously, execute the following command.

Get-AzureRmResourceGroup | Select-Object ResourceGroupName,Location

List Resource Group

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"

Common Variables

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.

Get Credentials

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

Subnet Details

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 -Subnet $subnetConfig

VNET Details

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
 Public IP Address

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

NSG Rule

Next, define a variable containing a network security group.

$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location -Name windowsCloudNetworkSecurityGroup -SecurityRules $nsgRuleRDP

NSG Group

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

NIC Details

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

VM Config Details

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

Create Windows VM

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.

VM Created

Congratulation, Windows VM is created!! 😊

You can verify the Virtual Machine through the Azure Portal also, login to Azure portal -

On the left Hub menu, click All resources and select the newly created Windows virtual machine, seems to appear the VM Status Running.

VM Overview

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.

VM Overview - Public IP

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.

Download RDP

You will get a Save As dialog box subsequently by clicking the button, save the connection file in your preferred place.

Save As

You can connect the server using Connect option, right click of RDP file – Connect.

RDP 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.

Windows VM Connected

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.

Install GNOME desktop and enabling RDP access to an Azure Ubuntu Linux VM

Ubuntu Linux VM

Microsoft Azure and Ubuntu Linux VM

In previous posts already we have been walking through about the Cloud Computing and Microsoft Azure in addition how to setup an Ubuntu Linux VM on Azure using Azure Portal as well as PowerShell.

We came to know that the Cloud Computing is a trending buzzword in the recent IT industry and gives the facility and feasibility accessing a massive pool of computing resources provided by the diverse Cloud Providers such as Microsoft, Amazon or Google on the basis of something Pay-As-You-Go model.

In this sequence the Microsoft Azure is one of leading cloud computing platfroms which provide a wide range of cloud services counting with Platform as a Service (PaaS) and Infrastructure as a Service (IaaS) to develop and scale applications as well deploy and manage through a global network of data centers.

If we talk about the VM, an Azure Virtual Machine (VM) is an on-demand, high-scale, secure computing resource deployed on Azure through different methods, gives more control over the computing environment. In addition the Ubuntu Server is a part of the larger set of Ubuntu products and operating system developed by Canonical and open source programmers around the world.

You can visit some previous posts to know a bit more about the following topics – 

GNOME Desktop

GNOME Desktop

GNOME is the Windows-like desktop environment a graphical interface that works on Unix and Unix-like systems and composed entirely of free and open source software. It is the default version which runs on major Linux distributions like Ubuntu, Red Hat Enterprise Linux, Oracle Linux, SUSE Linux Enterprises etc. 

GNOME stands as GNU Network Object Model Environment, a part of the GNU project, but the acronym was dropped because no longer reflected the vision of the GNOME projetc. The main objective of GNOME is to provide a user friendly suite of applications and easy to use desktop on top of Linux environment somewhat very similar to the Windows operating system.

Visit to know more about the GNOME -

xRDP Server

xRDP Server

In fact, Windows to Linux based remote desktop connectivity is often bandwidth exhaustive, insecure and difficult to configure. Now consider a scenario where a remote Windows user required to connect a Linux system as simple as connecting to a Windows system.

xRDP is an open source remote desktop protocol server, which uses RDP that enables operating systems other than Microsoft Windows (like Ubuntu Linux) to deliver a fully functional RDP compatible remote desktop experience. The xrdp package provides RDP functionality, along with an X server capable of accepting connections from rdesktop, freerdp and Windows Terminal Server clients.

Visit to know more about the xRDP -


We are aware that SSH is the default method when connecting to an Ubuntu server deployed on Azure cloud and how to connect the same we already went through. Here we will see the steps involved in installing the GNOME desktop and xRDP packages on an Ubuntu Linux Virtual Machine (VM) running on top of Azure. It makes available a more familiar and user friendly remote desktop style connection.

Before moving ahead, we need some pre-requisites to go ahead installing GNOME and xRDP on an Ubuntu Linux VM - 
  1. Azure subscription, if you don't have an account then sign up for a free Azure account -
  2. A running Ubuntu Linux VM
  3. PuTTY client to be used as the SSH client
  4. Some Hands on with Linux commands

STEP – 1: Validate the existence of an Ubuntu VM

It is essential to exist an Ubuntu Linux Azure Virtual Machine (VM) to accomplish this demo task, login to the Azure portal

On the left Hub menu, click All resources and select the existing Ubuntu virtual machine, verify the VM is either running or stopped, if it is in stop mode, i.e. deallocated then start the same.

VM Status

STEP – 2: Fetch the connection details of Ubuntu VM

Next, required to connect the VM, you can go with either SSH key or PuTTY client depends on the configuration and setup done with Ubuntu VM. 

I am moving ahead with PuTTY client, click the Connect button from the menu bar to launch the connection details.

Connection details

Here you can see a new blade as Connect to virtual machine appeared, copy the account details which exist under the Login using the VM local account, in my case - ssh demoadmin@

STEP – 3: Connect the VM using PuTTY client

Since the Ubuntu Linux VM is configured in such a way to connect using the PuTTY client, so open up PuTTY, and in the Session page, submit the host name into the Host Name box, the same we copied earlier.

For example, in my case, it was - ssh demoadmin@, but need to submit only demoadmin@, exclude the ssh prefix and then, under Connection type, select SSH and click Open.


Once the SSH session has been established, promptly, it will ask password for the connecting server, enter the administrator password you specified during provisioning the Ubuntu VM.

Connecting Ubuntu

Post authorization, you will be connected with the Ubuntu Linux 18.04.1 LTS Virtual Machine (VM).

Ubuntu Connected

STEP – 4: Update the package

Next, before looking the installation the desktop, required to update the package list to make sure we have all essentials newest versions of the packages and their dependencies.

Execute the following command to accomplish this.

sudo apt-get update
Execute Update package command

It will start the updating, the time you execute the command and sooner updating list will be complete.

Package Updating done

STEP – 5: Install the GNOME desktop

Time to begin the desktop installation, execute the following command to install GNOME desktop from within the terminal session.

sudo apt-get install ubuntu-gnome-desktop

Install Gnome Server

Quickly the installation will be proceeding as soon you execute the above listed command, follow up with one confirmation.

Gnome desktop Installed

Proceed with submitting the yes as Y and the system will continue to install and align the required files and libraries etc.

Gnome desktop installation completed

It will take a couple of moments the installation process, depending on the configuration of VM, etc. but preferably you will get the successful completion acknowledgement.

Installation process done

Congratulations, the GNOME desktop has been installed!! 😊

STEP – 6: Install the xRDP Server

Now the GNOME server has been installed successfully, time to install xRDP, an open source remote desktop protocol (RDP) server which allows you to RDP to your Ubuntu Linux server from a Windows machine.

Execute the following command to install the xRDP package.

sudo apt-get install –y xrdp

Install xRDP package

Sooner it will process and finish the installation the xRDP server.

xRDP installed

STEP – 7: Configure Console Access

GNOME and xRDP has been installed, but yet we have to configure a couple of settings. In this series by default the console access is restricted to root that means connections by anyone else will be dropped.

Execute the following command to change access to the console from the root only to all users, simply edit the Xwrapper.config file.

sudo nano /etc/X11/Xwrapper.config

Configure console access

It will launch the configuration file under the nano editor, essential to manually change the line allowed_users=console to allowed_users=anybody.

Edit the Xwrapper config file

XWrapper config file configured

Apart from the above listed way, you can also execute the following command to make the changes.

sudo sed -i 's/allowed_users=console/allowed_users=anybody/' /etc/X11/Xwrapper.config

Alternative way

STEP – 8: Adding NSG rule for RDP traffic

In fact, we are dealing with an Ubuntu Linux VM where the machine has been deployed with a Network Security Group (NSG) that allows port 22 inbound for SSH communication by default, not 3389 which is essential for an RDP connection.

Move to the Azure Portal, select the Ubuntu Linux virtual machine and click the Networking under the Settings section, will launch the Inbound as well Outbound Port Rules blade.

NSG rules

Do validate if you already allowed RDP via 3389 Port during the provisioning of Ubuntu VM or not, if not then add an inbound security rule for the same.

Inbound rule

STEP – 9: Connecting the Ubuntu VM via RDP

Next, time to verify the RDP connection, move to Ubuntu VM Overview blade and copy the Public IP address which will be used to connect he server using RDP.

VM Overview blade

Subsequently, I am connecting from a Windows machine, hereafter will use the mstsc utility to connect the server remotely.

Remote Desktop Connection

As soon you connect the server the xRDP login screen will be appeared.

xRDP login screen

Go ahead and provide the user credentials and proceed by clicking the OK button. Post submission of the correct username and password you will get an Authentication Required popup, since the first time you remotely logged on the Ubuntu desktop.

Gnome Authentication Pop Up

Either you can cancel the authentication or go ahead passing the password, sooner the GNOME desktop will be available.

Gnome Desktop

You can notice that the Ubuntu Dock is not visible, but if you click the Activities menu under the top will get a couple of options.

Gnome Ubuntu Dock

Congratulations, Ubuntu Linux VM connected remotely !! 😊

In the short-term, here in this article, we walked through the outline of GNOME desktop and xRDP package as well their installation besides connecting to the Ubuntu server. 

Keep visiting for further posts.