Connect-Mstsc – New version in TechNet Script Gallery

My Connect-Mstsc function was overdue for an update and I took the opportunity to add some additional feature to Connect-Mstsc as well. The purpose of this function is to start an RDP session with the specified user name and password. This functionality is not included in the mstsc.exe tool, which is why I wrote this script. The script is available for download in the TechNet script library: Connect-Mstsc.

This script accepts many parameters but two things need to be present, the ComputerName and either the combination of a User and a Password or a Credential object which will be used to authenticate the user against the remote system.

A simple example of how to use this function is as follows:

Connect-Mstsc -ComputerName server01 -User contoso\jaapbrasser -Password supersecretpw

A remote desktop session to server01 will be created using the credentials of  contoso\jaapbrasser

Alternatively the -Credential parameter can be used to connect to a remote host:

Connect-Mstsc -ComputerName -Credential $Cred

A RDP session to the system at will be created using the credentials in   the $cred variable

The complete function is available in the TechNet Script Library. To view this script or to participate in the discussions about this script either comment here or in the TechNet Script Gallery. Because some of the new functionality, specifically the parameter sets and support for common parameter, the latest version of Connect-Mstsc is not compatible with PowerShell 2.0. To remedy this problem I have uploaded a PowerShell 2.0 compatible version as well.

TechNet Script Library
My entries in TechNet Script Gallery
Connect-Mstsc (PowerShell 2.0)

2 thoughts on “Connect-Mstsc – New version in TechNet Script Gallery

  1. James C


    How to create a script that uses connect-mstsc to connect to a remote server and then execute a command (such as ipconfig) on that remote server?


    James C

    1. Jaap Brasser Post author

      Hello James,

      Connect-Mstsc establishes a Remote Desktop Connection to another system. A RDP session is not meant for automation but for user interaction. If you would like to remotely execute commands on another system you could use PowerShell Remoting instead. For example by using the Invoke-Command or Enter-PSSession cmdlets. Alternatively you could also use WMI or even the sysinternals PSexec tool.


Leave a Reply

Your email address will not be published.