Skip to content

Instantly share code, notes, and snippets.

@boranbar
Created July 14, 2025 16:05
Show Gist options
  • Select an option

  • Save boranbar/843d6fdf68f6a73b92994663e9db1ff3 to your computer and use it in GitHub Desktop.

Select an option

Save boranbar/843d6fdf68f6a73b92994663e9db1ff3 to your computer and use it in GitHub Desktop.
PowerShell script to change the default Remote Desktop Protocol (RDP) port on Windows, remove flood protection limits, and automatically configure the Windows Firewall.
# Yeni RDP Port Numarası (gerekirse bu değeri değiştirin)
$NewRdpPort = 42500
Write-Host "🔧 RDP ayarları yapılandırılıyor..." -ForegroundColor Cyan
# 1. RDP Flood limitlerini kaldır
Write-Host "⚙️ Flood limit ayarları kaldırılıyor..." -ForegroundColor Yellow
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -Name "MaxOutstandingConnections" -Value 0 -PropertyType DWord -Force | Out-Null
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -Name "MaxConnectionTimeOut" -Value 0 -PropertyType DWord -Force | Out-Null
# 2. RDP Portunu değiştir
Write-Host "📡 RDP portu $NewRdpPort olarak ayarlanıyor..." -ForegroundColor Yellow
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name "PortNumber" -Value $NewRdpPort
# 3. Yeni port için firewall kuralı oluştur
Write-Host "🛡️ Yeni firewall kuralı ekleniyor (Port $NewRdpPort)..." -ForegroundColor Yellow
New-NetFirewallRule -DisplayName "RDP Custom Port $NewRdpPort" -Direction Inbound -Protocol TCP -LocalPort $NewRdpPort -Action Allow
# 4. Hizmeti yeniden başlat
Write-Host "🔄 RDP servisi yeniden başlatılıyor..." -ForegroundColor Cyan
Stop-Service -Name TermService -Force
Start-Service -Name TermService
Write-Host "✅ RDP yapılandırması tamamlandı! Lütfen yeni port üzerinden bağlantı kurun." -ForegroundColor Green
@boranbar
Copy link
Author

boranbar commented Jul 14, 2025

RDP Port Change Script - Usage Instructions

This guide explains how to run the rdp_change.ps1 script to change the default RDP port and configure firewall rules on Windows.


📥 1. Save the Script

  1. Open Notepad (or any text editor).
  2. Copy and paste the entire contents of the rdp_change.ps1 script.
  3. Save the file to your Desktop as: rdp_change.ps1

🧑‍💻 2. Run the Script with Administrator Privileges

  1. Right-click on PowerShell and choose "Run as Administrator".
  2. In the PowerShell window, type the following commands:
cd ~\Desktop
powershell -ExecutionPolicy Bypass -File .\rdp_change.ps1

⚠️ Important Notes

  • The script uses a static RDP port, which is defined at the top of the script file:

$NewRdpPort = 42500

If you want to use a different port number, you must manually edit this line before running the script.
Make sure the new port is not already in use and that it is allowed through your firewall or network policies.

After changing the port, you will need to connect to your machine using the new format:

your-ip:NEW_PORT

For example, if you changed the port to 3399, you would connect like this:

192.168.1.10:3399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment