How to rdp to azure Vm in unattended mode from command line terminal

Viewed 72

Found the Microsoft document . but it ask for user prompt.

so is there any way to Rdp without user credentials(without user prompts) ?

1 Answers

If you have the IP, you can do in Powershell:

$rdpIp = "dottedIP.or.DNSName.of.VM"

cmdkey /generic:TERMSRV/$rdpIp /user:username /pass:"password"
mstsc /v:$rdpIp
cmdkey /delete:TERMSRV/$rdpIp

Going a step further, if you install Powershell Secrets Management (and configure a secret store as documented), you can set up a credential as follows:

#isolate your username and password from the connection script itself
Set-Secret -Name MyRDPUserName -Secret "MyUserNameValue"
Set-Secret -Name MyRDPPassword -Secret "MyPasswordValue"

and then the script to connect looks like:

$rdpIp = "dottedIP.or.DNSName.of.VM"
#get the secrets from the store
$user = Get-Secret -Name MyRDPUserName -AsPlainText
$pass = Get-Secret -Name MyRDPPassword -AsPlainText

cmdkey /generic:TERMSRV/$rdpIp /user:"$user" /pass:"$pass"
#erase the values from your Powershell session
$user = $null
$pass = $null

mstsc /v:$rdpIp

#remove the stored credential
cmdkey /delete:TERMSRV/$rdpIp
Related