Update to Connect-Mstsc script, RDP Session with credentials

A request came in for additional functional of my Connect-Mstsc script and I decided to add the -Admin parameter to this script. I have published the latest version of this script at the Technet Script Gallery:

Connect-Mstsc – Open RDP Session with credentials

Here are some example of how the script can be used:

. .\Connect-Mstsc.ps1 
This command dot sources the script to ensure the Connect-Mstsc function is available in your current PowerShell session 
Connect-Mstsc -ComputerName server01 -User contoso\jaapbrasser -Password supersecretpw 
A remote desktop session to server01 will be created using the credentials of contoso\jaapbrasser

5 thoughts on “Update to Connect-Mstsc script, RDP Session with credentials

  1. Pingback: Snippet: Extending Connect-MSTSC for fun and profit ¶ devops.fixt.co

  2. Mark Stoopman

    HI Jaap,

    Do you know if there’s any change to connect to a remote desktop server via a gateway?
    I’d like to monitor a cloud hosting provider foor availability and performance byj logging on an d off every 10 minutes or so.
    We use PRTG which , sadly, doesn’t support connections through a gateway

  3. Jaap Brasser Post author

    If monitoring is what you are trying to do, wouldn’t simply checking if the server respond on the RDP port be a solution.

    Alternatively you could save a .RDP file that contains the RDP Gateway server configured and connect to the system with a command similar to this:

    mstsc.exe .\YourStoredConnection.rdp

    1. Mark Stoopman

      Hi Jaap,
      Thanx for yr reply.
      it is actually a bit more than monitoring.
      I’d like to monitor every 10 minutes if it is possible to login on the system and logout again.
      Monitoring the port only is not enough since I can only monitor the rds gateway which runs on another system.
      The problem my client faces now is that all clients are disconnected from the system a couple of times a day, and auto-reconnect can last up to 10-15 times until the user is loggin again. In that period the internet connection is simply alive and also the ssl and rdp ports to the gateway are still accessible.

  4. Steven

    Hi Jaap,

    is there a problem with your scrip? i tried it under w10, w2k8r2 and w2k12r2 and it is not working either.
    I could start the script but the mstsc.exe wont start.
    Do you have any idea what that could be?

    BR Steven


Leave a Reply