Skip to content

diegofercri/windows-rdp-port-switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🔐 RDP Port Changer for Windows

PowerShell script to securely and interactively change the Remote Desktop (RDP) port on Windows systems.

📋 Features

  • ✅ Modify RDP port directly via Windows Registry
  • ✅ Automatically configure Windows Firewall rules
  • ✅ Validate port availability before applying
  • ✅ Warn if using commonly reserved ports
  • ✅ Restore default RDP port (3389) anytime
  • ✅ Option to restart RDP service automatically
  • ✅ Check for administrator privileges
  • ✅ Interactive interface with language support
  • ✅ Multi-language support: English & Spanish

🛠️ Requirements

  • Windows 10/11 or Windows Server 2016/2019/2022
  • PowerShell 5.0 or higher
  • Administrator permissions

🚀 Installation

  1. Download switcher.ps1
  2. Place it in an accessible folder (e.g., C:\Scripts)

📖 Usage

First-Time Setup

If you've never run custom PowerShell scripts:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

Run the Script

# Navigate to script location
cd C:\Scripts

# Run interactively
.\switcher.ps1

Optional Parameters

# Directly change to a specific port
.\switcher.ps1 -NewPort 5252

# Show current RDP port
.\switcher.ps1 -ShowCurrentPort

# Restore default RDP port (3389)
.\switcher.ps1 -RestoreDefault

# Specify interface language
.\switcher.ps1 -Language EN  # English (default)
.\switcher.ps1 -Language ES  # Spanish

Run Without Changing Execution Policy

powershell -ExecutionPolicy Bypass -File ".\switcher.ps1"

🔍 Verification

After running the script:

# Get the configured RDP port
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name "PortNumber"

# Check if the port is listening
netstat -an | findstr ":<NEW_PORT>"

# View firewall rules
Get-NetFirewallRule -DisplayName "RDP-Custom-*" | Format-Table DisplayName, Enabled

💻 How to Connect After Changing Port

Windows (MSTSC)

mstsc /v:192.168.1.100:5252

Or in GUI:
Computer: 192.168.1.100:5252

Remember to configure port forwarding in your router if accessing externally.

⚠️ Security Best Practices

  • Avoid using common ports (e.g., 21, 22, 80, 443)
  • Use high dynamic ports (49152–65535) to reduce attack vectors
  • Always document your new port for future access
  • Combine with other security tools: firewall, 2FA, etc.

🛠️ Troubleshooting

Script Doesn’t Run

  • Run PowerShell as Administrator
  • Check execution policy:
Get-ExecutionPolicy

Can't Connect After Change

# Restart RDP service
Restart-Service TermService -Force

# Ensure RDP is enabled
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
  • Check firewall and router settings

Port in Use

netstat -an | findstr ":5252"
  • Try a different unused port

📝 Changelog

v1.0.0

  • Initial release
  • Basic RDP port changing and firewall config
  • Multi-language support (EN/ES)
  • User prompts and error handling

🤝 Contributing

Contributions welcome!

  1. Fork this repo
  2. Create a branch: git checkout -b feature/NewFeature
  3. Commit changes: git commit -m "Add NewFeature"
  4. Push: git push origin feature/NewFeature
  5. Submit a Pull Request

📄 License

This project is licensed under the MIT License – see the LICENSE file for details.

👤 Author

diegofercrihttps://diegofercri.dev