@GitHub Copilot - Welcome @BanterBoy, I’m your Copilot and I’m here to help you get things done faster. I can identify issues, explain and even improve code.

You can ask generic questions, but what I’m really good at is helping you with your code. For example:

Generate unit tests for my code Explain the selected code Propose a fix for the bugs in my code If you want to learn more about my capabilities and limitations, check out the Copilot documentation.

I’m powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

@BanterBoy: - Explain what the script does and why it is useful.

@GitHub Copilot - This is a PowerShell script that is used to remove a user session from a remote desktop. The script is called Remove-RDPUserSession.ps1 and it is written by Luke Leigh. The script is well documented with comments that explain the purpose of the script, the author’s information, and links to the author’s website, LinkedIn, and GitHub.

The script uses the CmdletBinding attribute to define the default parameter set, confirm impact, and help URI. The script also uses the Alias attribute to define an alias for the cmdlet. The script defines two parameters: ComputerName and IdentityNo. The ComputerName parameter is used to specify the name, IP, or FQDN of the computer that the user session is running on. The IdentityNo parameter is used to specify the ID of the user session that needs to be removed.

The script uses the reset session command to remove the user session. The reset session command is executed with the IdentityNo and ComputerName parameters. The script is well written and easy to understand.

To improve the readability of the code, the author could consider adding more comments to explain the purpose of each section of the script. Additionally, the author could consider using more descriptive parameter names to make it easier for other developers to understand the purpose of each parameter. Finally, the author could consider adding error handling to the script to make it more robust.

@BanterBoy: - Explain how to use the script and provide examples.

@GitHub Copilot - Sure, here are some examples of how to use the script:

Example 1: Remove a user session with ID 2 from a computer named DANTOOINE

Remove-RDPUserSession -ComputerName DANTOOINE -ID 2

Example 2: Remove a user session with ID 3 from a computer with IP address

Remove-RDPUserSession -ComputerName -ID 3

Example 3: Remove a user session with ID 4 from a computer with FQDN

Remove-RDPUserSession -ComputerName -ID 4

Note that you will need to have administrative privileges on the remote computer in order to remove a user session.


function Remove-RDPUserSession {
        Function to extend the use of the QUser Command.

		This function can be used to extend the use of the QUser Command in order to levy some addition automation. This command will query the Server/s specified and output the session details ( ID, SessionName,LogonTime, IdleTime, Username, State, ServerName).

		These details are output as objects and can therefore be manipulated to use with additional commands.

		Remove-RDPUserSession -ComputerName DANTOOINE -ID 2

		ID          : 2
		SessionName : rdp-tcp#7
		LogonTime   : 25/03/2020 01:49
		IdleTime    : 2:41
		Username    : administrator
		State       : Active
		ServerName  : DANTOOINE

		Author:     Luke Leigh



	[CmdletBinding(DefaultParameterSetName = 'Default',
		SupportsShouldProcess = $false,
		PositionalBinding = $false,
		HelpUri = '',
		ConfirmImpact = 'Medium')]
	Param (
		# Enter the Name/IP/FQDN for the computer you would like to retrieve the information from or pipe in a list of computers.
		[Parameter(ParameterSetName = 'Default',
			Mandatory = $false,
			ValueFromPipeline = $true,
			ValueFromPipelineByPropertyName = $true,
			ValueFromRemainingArguments = $true,
			Position = 0,
			HelpMessage = 'Enter the Name/IP/FQDN for the computer you would like to retrieve the information from or pipe in a list of computers.')]

		[Parameter(ParameterSetName = 'Default',
			Mandatory = $false,
			ValueFromPipeline = $true,
			ValueFromPipelineByPropertyName = $true,
			HelpMessage = 'Enter User ID for the Session you would like to shut down or pipe input.'


	reset session $IdentityNo /server:$ComputerName


Back to Top


Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.

Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.


Back to Top