Created
September 10, 2017 00:43
Disconnect from a RDP session without locking the screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RDP-Disconnect.ps1 | |
# Disconnect from a RDP session without locking the screen. Useful for headless gaming machines. | |
# Tested with Windows 10 only | |
# Elevate to Admin | |
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } | |
# Find active session and switch to console | |
$session = query session | sls 'Active' | |
$sessionId = $session.toString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[2] | |
tscon $sessionId /dest:console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment