如何从命令行终端以无人值守模式 rdp 到 azure Vm

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

找到微软document。但它要求用户提示。

那么有什么方法可以在没有用户凭据的情况下(没有用户提示)进行 Rdp 吗?

如果你有IP,你可以在Powershell中做:

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

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

更进一步,如果您安装 Powershell Secrets Management(并按照文档配置秘密存储),您可以按如下方式设置凭据:

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

然后连接脚本如下所示:

$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