Tag Archives: RDP

New versions of Connect-Mstsc and Get-OrphanHomeFolder in TechNet Script Gallery

One of the things that keeps me busy is maintaining the library of scripts I have made available in the TechNet Script Library. I get a good number of questions and requests about my scripts there and I enjoy picking out some of the interesting or useful requests to implement them in my scripts. Recently I received some requests for new functionality in some of my scripts so I decided two of my scripts for the latest round of updates.

For Connect-Mstsc I have updated both the PowerShell 3.0 and up version as well as the version that is backwards compatible with PowerShell 2.0. A new parameter has been introduced, -Public, which corresponds with the /public switch of the mstsc.exe tool. It runs Remote Desktop in public mode, which was requested by MSFTW. Here is an example of this switch parameter in action:

.EXAMPLE   
Connect-Mstsc -ComputerName server01:3389 -User contoso\jaapbrasser -Password supersecretpw -Public

Description 
-----------     
A RDP session to server01 at port 3389 will be created using the credentials of contoso\jaapbrasser and the /public switch will be set for mstsc

Get-OrphanHomeFolder has been updated to support wildcards/regular expressions to be able to exclude folders. This came from a request of martin_i who has a lot of folders named .v2 which he would like to exclude instead of manually specifying each path. Here is an example:

.EXAMPLE    
.\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\Server02\Fileshare\Home -MoveFolderPath \\Server03\Fileshare\MovedHomeFolders -ExcludePath '\.v2$' -RegExExclude 
 
Description: 
Will list all the folders in the \\Server02\Fileshare\Home folder and will move orphaned folders using robocopy, excluding folders that end with .v2

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
Script to get orphaned home folders and folder size
Connect-Mstsc – Open RDP Session with credentials
Connect-Mstsc – Open RDP Session with credentials (PowerShell 2.0)

Disconnect-LoggedOnUser – Disconnect a RDP session remotely

I created a new function that wraps around the rwinsta commandline-tool to remotely disconnect RDP sessions. I created this function to simplify cleaning up open RDP sessions, for example when an administrator leaves the company there might be disconnected RDP sessions by this user. This scripts works in combination with the Get-LoggedOnUser script to simplify finding and disconnecting these sessions. The script is available for download in the TechNet Script Gallery: Disconnect-LoggedOnUser.

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

.EXAMPLE 
Disconnect-LoggedOnUser -ComputerName server01 -Id 5 
 
Description 
----------- 
Disconnect Session Id 5 on server01 

In the next example the output of the Get-LoggedOnUser script is filtered by Where-Object and then piped into the Disconnect-LoggedOnUser script:

.EXAMPLE 
.\Get-LoggedOnUser.ps1 -ComputerName server01,server02 | Where-Object {$_.UserName -eq 'JaapBrasser'} | Disconnect-LoggedOnUser -Verbose 
 
Description 
----------- 
Use the Get-LoggedOnUser script to gather the user sessions on server01 and server02. Where-Object filters out only the JaapBrasser user account and then disconnects the session by piping the results into Disconnect-LoggedOnUser while displaying verbose information. 

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.

TechNet Script Gallery
My entries in TechNet Script Gallery
Disconnect-LoggedOnUser
Get-LoggedOnUser

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:

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

Description 
----------- 
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:

.EXAMPLE
Connect-Mstsc -ComputerName 192.168.1.10 -Credential $Cred

Description 
----------- 
A RDP session to the system at 192.168.1.10 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
Connect-Mstsc (PowerShell 2.0)

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:

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