Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Created November 22, 2025 01:40
Show Gist options
  • Select an option

  • Save HauptJ/40feecb3a357cc7e45ff6c72d89bf4a8 to your computer and use it in GitHub Desktop.

Select an option

Save HauptJ/40feecb3a357cc7e45ff6c72d89bf4a8 to your computer and use it in GitHub Desktop.
PowerShell script to enable RDP, and disable sleep timeout on Windows.
#Requires -RunAsAdministrator
param (
[bool] $optRestart = $false,
[bool] $optDisableSleep = $false
)
try {
$rdpStatus = Get-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\' -Name "fDenyTSConnections"
# if 1 RDP is disabled
if($rdpStatus.fDenyTSConnections -eq 1) {
Write-Output "RDP is disabled - enabling it"
# Enable RDP
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\' -Name "fDenyTSConnections" -Value 0
# Enable RDP through the firewall
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
} elseif ($rdpStatus.fDenyTSConnections -eq 0) {
Write-Output "RDP is already enabled"
} else {
Write-Output "An unknown error occured when trying to determine the status of RDP status: $rdpStatus"
}
if($optDisableSleep){
Write-Output "Disabling System Sleep Timeout"
powercfg -change -standby-timeout-ac 0
}
if($optRestart){
Write-Output "Restarting System"
Restart-Computer
}
} catch {
Write-Output "An error occured"
if($Error.Count -gt 0) {
foreach($err in $Error){
Write-Output "Error: $err"
}
}
Exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment