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,970 times
Add to favorites
E-mail Twitter Digg Facebook
  • Bypassing certificate issue popup.
    1 Posts | Last post November 28, 2017
    • I am successfully able to connect to remote-host but, everytime a popup comes 'The identity of a remote computer cannot be identified.Do you want to connect to it anyway?'
      This I am handling manually, but I want to know if your script provides any option to bypass the Popup. In description, I can't find the option to do such.
      Issue is that the host is not fixed each time each time it is executed, that's why I want this.
      Any help is appreciated.
  • connection is not working from win 2012R2
    1 Posts | Last post November 14, 2017
    • Hello Jaap
      I use this scrip on win 2008r2 server and is running without issue. But when I moved it to another server with win 2012R2 it's not able to connect to another win 2008 r2 servers. There is always popup window asking for credentials. 
  • Connecting via Gateway
    3 Posts | Last post June 12, 2017
    • Hi Jaap,
      is it possible to connect via gateway (Remote Desktop Gateway)?
      How do we do that?
      Thank you,
    • I was able to modify the script so it can incorporate an RD Gateway. I added a parameter for $RDPfile
              [ValidateScript({Test-Path -Path $_ })]
                  [string[]]     $RDPfile
      Then in the "begin" section of the function, I added a switch line (to the top of the list) that looks like this:
                  {$RDPfile}    {$MstscArguments += $RDPfile + ' '} #adds file path plus trailing space
      This worked fine for me. Hope it helps you.
    • Sorry. I should have mentioned that this solution I gave includes saving the RD Gateway information to an .rdp file and calling that file when you run the function so that it includes the RD Gateway.
  • Script runs with no errors but doesn't launch mstsc
    3 Posts | Last post April 20, 2017
    • First off the script looks great and I appreciate you posting it :). I am running the script and I have set the execution policy to bypass and have sourced it with . .\Connect-Mstsc but when I run the script with all the parameters it seems to run I get no errors but mstsc never launches, any suggestions what I should look at? 
    • same problem here. i tried it under server 2008 r2, w10 and server 2012 r2. 
      the script isn't working anymore
    • How are you running the script, could you try running the following and let me know what the output is:
      . .\Connect-Mstsc.ps1 
      Connect-Mstsc -ComputerName server01:3389 -User contoso\jaapbrasser -Password supersecretpw -Verbose
      Jaap Brasser
  • How to connect to Azure VMs
    2 Posts | Last post March 01, 2017
    • I supplied user name and password, and doing something like this. 
      cmdkey /add:$Server /user:$User /pass:$password
      mstsc /v $server
      This still asks me for the credentials... Any thoughts? 
    • Never mind. figured out. the server has to be set without the port! 
  • I am connecting to Windows 8 machine remotely like below:
    1 Posts | Last post February 24, 2017
    • Connect-Mstsc -ComputerName "XXX" -Credential $mycred
      I am able to login to server but server is asking to click on "OK" button to agree some of the policies. So could you please help me to bypass the button click step so that i can login to server directly.
      Dommeti Raveendra
  • Pass a text file with servers
    2 Posts | Last post January 24, 2017
    • Is there a way to pass a text/csv file with a list of servers. Then once verified to be logged in it logs off the user?
    • Sure you could build something like this using Connect-Mstsc, what is your end goal of this. Is this to verify if a user has the correct rights, if the corrects ports have been opened or all of the above?
      Jaap Brasser
  • Local Resources > Keyboard > Apply Windows Key Combinations
    2 Posts | Last post January 24, 2017
    • YB_
      Hello Jaap,
      I'm using your PowerShell script. It is working very well, I really appreciate it. But in the GUI of "mstsc" there's a few options in the Local Resources tab Keyboard section. It can allow you to use "Apply Windows Key Combinations" in 1)Only when using fullscreen 2)On this computer 3)On the remote computer.
      Is it possible that I can set these 3 flags using your script? 
      It is crucial for me to navigate among systems and send some keystrokes sometimes in local sometimes in remote systems. 
    • Hello YB,
      This is something I have been wanting to implement, because this is not part of the mstsc commandset I will have to develop a workaround to be able to set this. I have created a GitHub issue for myself to work on this issue, you can follow it here:
      Do you have any additional feature requests, perhaps I can include those in there as well.
      Jaap Brasser
  • connect without password
    2 Posts | Last post December 22, 2016
    • hi,
      is it possible to connect with this script, if my user havn't password ? 
      if i try Connect-Mstsc -ComputerName sr8-hv-scb1 -User intranet\$user -Password ""
      it doesn't works
    • Hello davzell,
      Currently this is not supported by the script, I could look into supporting this functionality. You would have to configure the correct policies, the default Windows policies do not allow for blank passwords to be used for remote connections.
      Jaap Brasser
  • Credentials Saved
    4 Posts | Last post November 02, 2016
    • Hi Jaap,
      The credentials seems to be saved. So when I use Mstsc to connect the old-fashion way later, I'm no longer prompted for credentials.
      Can I avoid this?
    • Hello Lars,
      Currently the script does not remove the credentials after logging in, so indeed this means that next time you manually connect using mstsc, the cached credentials will still be available. I have logged an issue for this on GitHub so you can follow the progress here:
      If you require a workaround right now let me know and I can give the command you can execute to clear the specific credentials from your local credential store.
      Jaap Brasser
    • Hi,
      Yes please. I would like the workaround command =)
      ./ Lars Olsen
    • Alright, then you can do something along these lines, just add in the appropriate server/domain name in the following command:
      cmdkey /delete:TERMSRV/
      Jaap Brasser
11 - 20 of 57 Items