Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

How to generate an Azure VM RDP file

·433 words·3 mins· 100 views · 5 likes ·
Connect-AzAccount Get-AzRemoteDesktopFile Get-AzSubscription Get-AzVM

Hi everyone, today I want to show you how to generate an Azure VM RDP file, either for a single virtual machine or for all the VMs in a resource group. Azure PowerShell has the Get-AzRemoteDesktopFile cmdlet that gets the RDP file for a selected VM.

Azure VM RDP

  • This tutorial assumes that you already have a Microsoft Azure account set up.
Azure PowerShell Workaround>

Azure PowerShell Workaround #

If you want to know how to install the PowerShell Azure module on your machine, check out this link. The simplest way to get started is to sign in interactively at the command line.


This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Select-AzSubscription -Subscription "My Subscription"

Once you set your default subscription, you’re ready to start.

Get a Remote Desktop file for a single VM>

Get a Remote Desktop file for a single VM #

In the following example, we use the cmdlet to save the RDP file for a specific VM.

Set the variables>

Set the variables #

Here, we define the characteristics of our virtual machine.

$resourceGroup = "RG-DEMO-NE"

$vmName = "VM-W10-DEMO"

We set the name of the RDP file and the location where we will store it.

$vm = Get-AzVM `
   -ResourceGroupName $resourceGroup `
   -Name $vmName

$fileName = $vm.Name +".rdp"
$localPath = "$home\Documents\AzureRDPs\" + $fileName

Using the -LocalPath parameter we can specify where to save the RDP file.

Get-AzRemoteDesktopFile `
   -ResourceGroupName $resourceGroup `
   -Name $vm.Name `
   -LocalPath $localPath

However, we can replace it with the -Launch parameter to initiate a remote connection instead of saving the file.

Get-AzRemoteDesktopFile `
   -ResourceGroupName $resourceGroup `
   -Name $vm.Name `

Important: If the VM is deallocated and does not have a static IP assigned, the generated RDP file will not have an IP address.

Get the remote desktop files for several virtual machines>

Get the remote desktop files for several virtual machines #

In this case, we use the following commands to save the RDP files for all virtual machines in the specific resource group.

 $resourceGroup = "RG-DEMO-NE"
 $vms = Get-AzVM `
   -ResourceGroupName $resourceGroup
 foreach ($vm in $vms)
    $fileName = $vm.Name +".rdp"

    $localPath = "$home\Documents\AzureRDPs\" + $fileName

    Get-AzRemoteDesktopFile `
      -ResourceGroupName $resourceGroup `
      -Name $vm.Name `
      -LocalPath $localPath

I hope you find this article useful and share it.

If you want to get more information about the Get-AzRemoteDesktopFile cmdlet, check out this link.