Skip to content

Instantly share code, notes, and snippets.

@Ran-Xing
Last active November 10, 2022 17:24
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 Ran-Xing/48772568b0ae15738766b25a8b014495 to your computer and use it in GitHub Desktop.
Save Ran-Xing/48772568b0ae15738766b25a8b014495 to your computer and use it in GitHub Desktop.
Change Remote Desktop Port
$portvalue = 33891
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" -Value $portvalue
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp' -name "PortNumber" -Value $portvalue
New-NetFirewallRule -DisplayName 'RDPPORTLatest-TCP-In' -Program "%SystemRoot%\system32\svchost.exe" -Profile Any -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portvalue
New-NetFirewallRule -DisplayName 'RDPPORTLatest-UDP-In' -Program "%SystemRoot%\system32\svchost.exe" -Profile Any -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portvalue
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber"
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp' -name "PortNumber"
net stop termservice
y
net start termservice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment