question

Jim2010Morrison2010-4207 avatar image
0 Votes"
Jim2010Morrison2010-4207 asked DaveKwas answered

RDP a server by command line

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
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

"Connect-Mstsc" is a function included in this download from the TechNet Script Gallery. Connect-Mstsc-Open-RDP-2064b10b


0 Votes 0 ·

Connect-AzAccount (To connect your Azure Account)
mstsc /v:00.000.00.00 (Put the Public ip of your VM)

Note: Be sure that you have installed the az-module by below command

Install-Module -Name Az


0 Votes 0 ·
AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered RichMatheisen-8856 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you Andreas for your reply.
But I have 100+ servers that I need to RDP. In this case are you saying I need to add my credentials for all those 100+ server by this command: cmdkey /generic:"<servername>" /user:"<username>" /pass:"<password>" ?
Also I tried what you suggested and it is not working for me. Still it is prompting me to enter password after getting the RDP window

0 Votes 0 ·

Have you included the Connect-Mstsc function in your PowerShell session by dot-sourcing it (either directly or in your PowerShell profile)???

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RicardoBohner-2520 avatar image
0 Votes"
RicardoBohner-2520 answered RichMatheisen-8856 commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you dont mind, can you please tell me how ?

0 Votes 0 ·

Search for "powershell create .rdp file" in whatever search engine you prefer!

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

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



mstsc1.jpg (83.1 KiB)
mstsc2.jpg (172.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaveKwas avatar image
0 Votes"
DaveKwas answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.