~/grkn/posts $ cat rdp-port-change-via-powershell.md

· 1 min read · DevOps · Author: Gürkan Biçer

RDP Port Change via PowerShell

Bu yazıyı Türkçe okuyun →

The script is changing RDP port on regedit and inserting firewall rules for related port.

$portvalue = 34545
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" -Value $portvalue
New-NetFirewallRule -DisplayName 'RDPPORT-TCP-In' -Profile 'Any' -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portvalue
New-NetFirewallRule -DisplayName 'RDPPORT-UDP-In' -Profile 'Any' -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portvalue

While i’m connected to customer windows server, i need to copy-paste following code snippet — because i’m lazy sysadmin ^^

I could write more information about remote desktop services and about the how to change remote desktop service port, but no need to detailed post.

Just remember, use different ports for remote desktop and only allow access from specific IPs.

← all blog posts