【问题标题】:How to rdp to azure Vm in unattended mode from command line terminal如何从命令行终端以无人值守模式 rdp 到 azure Vm
【发布时间】:2021-02-18 12:46:52
【问题描述】:

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

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

【问题讨论】:

    标签: virtual-machine rdp azure-vm


    【解决方案1】:

    如果你有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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多