Skip to content

Instantly share code, notes, and snippets.

@aus
Created September 10, 2017 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aus/1e812da7623f11fcdd983d56f58b2a74 to your computer and use it in GitHub Desktop.
Save aus/1e812da7623f11fcdd983d56f58b2a74 to your computer and use it in GitHub Desktop.
Disconnect from a RDP session without locking the screen
# 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