RDP Azure VMs using a GUI Utility

In this blog, I will review a simple GUI utility based on PowerShell, which Automatically connects an Azure VMs via the public IP, even if the public IP is dynamic or changed from some reason.

Especially in test or lab environments where VMs are being built and removed occasionally, public IP addresses get changed and therefore you need to redownload the RDP configuration from Azure portal.

To eliminate the constant RDP configuration download, the RDP utility allows you simply click the VM without knowing the public IP address and connect with username and password that can be saved as an encrypted file.

In addition to the RDP utility, you will be able to get many details about the VM like: VM status (Running/Deallocated), Disk name, OS type, OS version, size, and location.
At the VM info summery tab, you also can turn on the VM in one click.

Script parameters:

The first part of the script contains 3 parameters that can be changed inside the script to adjust it to your needs and settings:

  • The first parameter is the folder path, which contains the files for saving username and password:
    $Pathdir=”C:\Temp”
    In case the folder path doesn’t exists, it will be created, and this path can be changed of course.
  • The second parameter is the name of the text file which saves the username needed for the VM using RDP:
    $saveuser=”C:\temp\user.txt”
  • The third parameter is the name of the text file which saves the encrypted password (In case you would like to save it) needed for the VM using RDP:
    $savepass=”C:\temp\encpass.txt”

Running the script

Since the script based on PowerShell AZ module, verify that the AZ module is already installed on the machine.

The script includes 2 tab pages:

- VM Info Summary: This tab includes an information about the selected VM like VM status (Running/Deallocated), Disk name, OS type, OS version, size, and location, in addition you could turn on the VM in one click.

- RDP Connection: This tab allows you connect the selected VM using RDP if the VM has a public IP.

VM Summery tab:

  • At first, when running the script, a credential check will take place in order to verify that you are connected to Azure.
    In case your AZ Access Token is empty, a message box and a text message will appear:
  • Right after clicking the OK popup message, you will get the Azure Sign in window:
  • After the login process or in case you had an AZ Access Token, you will be able to see all the Azure subscriptions you owned:

In addition, the PowerShell console will display the current subscription context you are connected to:

  • After selecting the subscription, you will be able to see all the resource groups that exists at the subscription you have selected.
    When selecting the relevant resource group, a list of all the VMs in the resource group will be presented.
    In case the VM is turned on, the VM info summery will appear with green color like the next example:
  • In case the VM is turned on, the VM info summery will appear with black color like the next example:

RDP Connection tab:

  • At the RDP connection tab, you can select the VM you would like to RDP to and to select the option if to save the password within an encrypted file:
  • In case you try to RDP a VM which is turned off, you will get a popup message as the next screenshot:
  • In addition to the popup message at the PowerShell GUI utility, the VM name, public IP address and the VM state will be present at the PowerShell console as the next screenshot:
  • In case you try to RDP a VM which is turned on, a Remote Desktop Connection will automatically start and connect to the selected VM:
  • In addition to the popup message at the PowerShell GUI utility, the VM name, public IP address and the VM state will be present at the PowerShell console as the next screenshot:

The script

During the last 13 years, I'm working as a Senior Customer Succes Engineer (former PFE) at Microsoft. My areas of expertise are Exchange, Powershell & Azure.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store