My Get-LoggedOnUser script is available here: Get-LoggedOnUser

This function provides the functionality to disconnect a RDP session remotely by providing the ComputerName and the SessionId. It is build to work either as a stand alone function to disconnect RDP sessions remotely or the output of my Get-LoggedOnUser script can be directly piped into this function.

 

 

Version 1.0 - Initial Upload

 

 

 

PowerShell
Edit|Remove
Disconnect-LoggedOnUser -ComputerName server01 -Id 5
 

Disconnect session id 5 on server01

 

 

 

PowerShell
Edit|Remove
.\Get-LoggedOnUser.ps1 -ComputerName server01,server02 | Where-Object {$_.UserName -eq 'JaapBrasser'} | Disconnect-LoggedOnUser -Verbose
 

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.

 

 

 

 

PowerShell
Edit|Remove
<# 
.SYNOPSIS    
Function to disconnect a RDP session remotely 
     
.DESCRIPTION  
This function provides the functionality to disconnect a RDP session remotely by providing the ComputerName and the SessionId 
     
.PARAMETER ComputerName 
This can be a single computername or an array where the RDP sessions will be disconnected 
 
.PARAMETER Id 
The Session Id that that will be disconnected 
 
.NOTES    
Name: Disconnect-LoggedOnUser 
Author: Jaap Brasser 
DateUpdated: 2015-06-03 
Version: 1.0 
Blog: http://www.jaapbrasser.com 
 
.LINK 
http://www.jaapbrasser.com 
 
.EXAMPLE    
. .\Disconnect-LoggedOnUser.ps1 
     
Description  
-----------      
This command dot sources the script to ensure the Disconnect-LoggedOnUser function is available in your current PowerShell session 
 
.EXAMPLE 
Disconnect-LoggedOnUser -ComputerName server01 -Id 5 
 
Description 
----------- 
Disconnect session id 5 on server01 
 
.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. 
#>