Scenario
- We create a Windows Virtual Machine, with hostname that does not match the Azure resource name. For example, the Azure resource name might be:
someprojectname-test-vm and the Windows hostname spn-test-vm to satisfy the limitation of 15 characters long hostnames.
resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: vmName // <-- Azure Resource Name
location: location
properties: {
osProfile: {
computerName: computerName // <--- Windows Hostname (max 15 characters long)
- We enable Entra ID authentication installing the AADLoginForWindows extension.
Expectation
Using the az network bastion rdp --enable-mfa command to RDP into the VM using the native client in Windows should work. Instead, it fails with an error message "The target-device identifier in the request someprojectname-test-vm was not found in the tenant" like in the following picture:

Diagnosis and workaround
The problem occurs because the Windows VM is registered in Entra ID using the hostname (spn-test-vm), while the az network bastion rdp command assumes that the hostname matches the Azure resource name.
As a workaround, we can use the --configure flag, save the RDP file on disk, use a text editor to replace the name of the Azure resource with the hostname, and RDP successfully in the VM.
az network bastion rdp --name $bastionName --resource-group $resourceGroupName --target-resource-id $vmResourceId --enable-mfa --configure
Possible solution (maybe)?
Enrich the az network bastion rdp command to support specifying the hostname of the target VM, or obtain automatically the right hostname by Azure resource name?
It is not feasible to assume that the Azure resource name must match the Windows hostname in all cases because of the limitation of having 15 characters long hostnames. Azure resources can easily have longer names.
Scenario
someprojectname-test-vmand the Windows hostnamespn-test-vmto satisfy the limitation of 15 characters long hostnames.Expectation
Using the
az network bastion rdp --enable-mfacommand to RDP into the VM using the native client in Windows should work. Instead, it fails with an error message "The target-device identifier in the request someprojectname-test-vm was not found in the tenant" like in the following picture:Diagnosis and workaround
The problem occurs because the Windows VM is registered in Entra ID using the hostname (spn-test-vm), while the
az network bastion rdpcommand assumes that the hostname matches the Azure resource name.As a workaround, we can use the
--configureflag, save the RDP file on disk, use a text editor to replace the name of the Azure resource with the hostname, and RDP successfully in the VM.Possible solution (maybe)?
Enrich the
az network bastion rdpcommand to support specifying the hostname of the target VM, or obtain automatically the right hostname by Azure resource name?It is not feasible to assume that the Azure resource name must match the Windows hostname in all cases because of the limitation of having 15 characters long hostnames. Azure resources can easily have longer names.