RDP a server by command line

Jim2010 Morrison2010 1 Reputation point
2020-12-07T19:23:16.787+00:00

Hello,

Can someone please help me to share the command line that I can RDP servers using my user name and account.

Connect-Mstsc -ComputerName '<VM Name>' -User '<domain/username>' -Password '<password>'

When I tried the above command I am getting this error:

Connect-Mstsc : The term 'Connect-Mstsc' is not recognized as the name of a cmdlet, function, script file, or operable
program.

I tried this too, but no luck:
mstsc /v:<VM Name> -User '<domain/username>' -Password '<password>'

I am getting the RDP windows for those servers if I just use the below commands. But RDP window asking my password (User name is automatically taking):
Connect-Mstsc -ComputerName '<VM Name>'

Or

mstsc /v:<VM Name>

So my need is by a command line (user name and password), I need to connect the server via RDP properly.

Can someone please help ?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Andreas Baumgarten 97,486 Reputation points MVP
    2020-12-07T19:48:38.903+00:00

    It's not possible to add the username and password to the mstsc.exe.

    But this should work:

    # Create credentials
    cmdkey /generic:"<servername>" /user:"<username>" /pass:"<password>"
    # Connect MSTSC with servername and credentials created before
    mstsc /v:<servername>
    # Delete the credentials after MSTSC session is done
    cmdkey /delete:TERMSRV/<servername>
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    2 people found this answer helpful.

  2. Andreas Baumgarten 97,486 Reputation points MVP
    2020-12-07T20:19:34.353+00:00

    Could you please try the cmdkey without the quotes:

    cmdkey /generic:<servername> /user:<username> /pass:<password>
    

    If this doesn't work the next you can try:

    cmdkey /TERMSRV:<servername> /user:<username> /pass:<password>
    

    If you have 100+ servers you have to connect why you need to connect via command line? I just want to understand the use case.

    There are very good Remote Management Solutions on the market to get manage and connect via RDP to servers with integrated credential management. I am using Royal TS on a daily base: https://www.royalapps.com/ts/win/features


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

  3. Ricardo Bohner 1 Reputation point
    2020-12-07T20:35:23.013+00:00

    Why don't you create an *.rdp file you can add your username and password there. Than you run it via command line or however you want.


  4. Andreas Baumgarten 97,486 Reputation points MVP
    2020-12-07T21:34:38.663+00:00

    Saving the RDP config in a *.rdp file with MSTSC:

    Enter Servername and click on Show options

    45902-mstsc1.jpg

    Enter username and check the Allow me to save credentials
    Save the RDP file with Save as
    Connect to the server

    45800-mstsc2.jpg

    Here you will find a full how-to: https://www.nextofwindows.com/how-to-save-password-in-a-remote-desktop-connection-in-windows-8

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  5. DaveK 1,846 Reputation points
    2021-12-11T11:33:21.013+00:00

    Hi, I would recommend mRemoteNG as a connection manager. It allows you to import servers directly from AD or from a list in a text file and if a lot of the servers use the same credentials, it allows you to specify them at top level and choose per server if you inherit those creds or you can select certain servers for different creds as needed. Very useful if you manage lots of servers

    0 comments No comments