Change RDP Port from Powershell

The following is a guide to changing the RDP (Remote Desktop Protocol) port from powershell.


  1. Open your powershell as admin

  2. Then execute the command below. Replace xxxx with the port you want.


$portvalue = xxxx


Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" -Value $portvalue


New-NetFirewallRule -DisplayName 'RDPPORTLatest-TCP-In' -Profile 'Public' -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portvalue

New-NetFirewallRule -DisplayName 'RDPPORTLatest-UDP-In' -Profile 'Public' -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portvalue




  1. If so, Enter until it appears that the RDP port has changed.


Additional:

  • For security reasons, please do not change your RDP port to the default 3389 as it is prone to brute force attacks.

  • This RDP port change to be perfect requires a reboot process

  • The above command can only run in Powershell.


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.