Connect-Mstsc - Open RDP Session with credentials

This script allows you to open a Remote Desktop session with a remote session while specifying credentials. This functionality was removed from the mstsc.exe application and this PowerShell function can serve as a workaround that allows you to automatically connect to servers.

4.7 Star
44,944 times
Add to favorites
E-mail Twitter Digg Facebook
  • question
    2 Posts | Last post March 18, 2015
    • I heard that you cannot intract with rdp session due to security, will this fulfill it...bcas i am still gettting prombt any suggestion?
    • I'm not sure what you mean with interacting with an RDP session. It is indeed impossible to provide a username and password for the mstsc tool, that's why I wrote this script to provide the possibility of starting an RDP session from the console without having to enter additional credentials in the RDP session.
  • rdp to a different domain
    1 Posts | Last post March 17, 2015
    • Hi Jaap! Good afternoon. I was trying to use your script to automatically login to different computers from different domain using a single account. So lets say I do Connect-Mstsc, mis\jaapbrasser -password supersecretpw this command will let you login automatically and it will not ask you for a username and password, the issue now is when when you do this command Connect-Mstsc, mis\jaapbrasser -password supersecretpw after you enter that command it will still load rdp but it stops at the windows login screen where it ask you for a username and password. But when you do it normally like open rdp and enter the server name, username and password it lets you login with out any issues. Can you modify your script to include that function. Thanks
  • How to connect in mstsc /admin ?
    2 Posts | Last post July 08, 2014
    • Can you add the option please ?
    • I have updated the script to support this functionality, if you download Version 1.1 you will be able to specify the -Admin switch parameter in order to connect using the /admin swich of mstsc.
  • Start a program when you connect
    2 Posts | Last post July 08, 2014
    • Hi and thank you - this is a very useful script.
      Is there a way now to have something run automatically on the remote system when you connect?  I would like to automate the connection and once connected have an application run.
    • There is no direct way this script can assist you with that, this script calls mstsc.exe and starts a RDP session. Since the mstsc.exe tool does not support any automatic startup of applications there is nothing I could put in this script that would facilitate that.
      Depending on your situation you might be able to set this up using Remote Desktop Services:
      You could also attempt to do this by setting up an event trigger:
  • Password
    2 Posts | Last post July 08, 2014
    • Jaap,
      You have helped me in the past and this is going to be an awesome script. I just have one question is there a way to enter the password as a secure string? 
      With the way the script is when you enter the password it is entered as plain text.
      Below is what I have added to the end of your script and it works, just the password is readable when typed in. I tried to add the -assecurestring but it doesn't read the password then. Any help would be awesome.
      $server = Read-host "Connect To"
      $user = Read-Host "Username with domain"
      $password = Read-Host "Password"
      Connect-Mstsc $server $user $password
    • This is indeed possible to use it this way, actually what you are attempting to do is to build something that is already securely built-in PowerShell. What you would like to do is what Sayannara in the post above you has used, use Get-Credential to get the credentials, so you would end up with the following code:
      $server = Read-host "Connect To"
      $credential = Get-Credential
      Connect-Mstsc -ComputerName $Server -User $Credential.UserName -Password $credential.GetNetworkCredential().Password
  • get-credential with your function
    3 Posts | Last post July 08, 2014
    • Hi Jaap!
      Thanks a lot that's a brillant idea!
      Would it be possible to pass the credentials to your function with a variable obtained from get-credential?
      $cred = get-credential 
      Connect-Mstsc $server $cred.UserName $cred.Password $true
      I tried without success.
    • Well I answer to myself:
      $credential = Get-Credential
    • That is indeed the correct method of doing this, utilizing the PowerShell credential object to pass on the credentials to this function.
  • Little confuse on what this script does
    4 Posts | Last post July 22, 2013
    • Does this script allow you to open multiple Remote Desktop at once and the credentials are filled in. 
    • This script allows you to specify credentials to be used with an RDP session. This is functionality that does not exist in the mstsc.exe tool. This script provides you with a way to specify your credentials from the command line and allows you to then start one or multiple rdp connections with the credentials that you specified.
    • Nice idea the use of cmdkey!
      Easy but cool
    • Thanks Gastone, I am glad you like it!
51 - 57 of 57 Items