PowerShell script to securely and interactively change the Remote Desktop (RDP) port on Windows systems.
- ✅ 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
- Windows 10/11 or Windows Server 2016/2019/2022
- PowerShell 5.0 or higher
- Administrator permissions
- Download
switcher.ps1
- Place it in an accessible folder (e.g.,
C:\Scripts
)
If you've never run custom PowerShell scripts:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# Navigate to script location
cd C:\Scripts
# Run interactively
.\switcher.ps1
# 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
powershell -ExecutionPolicy Bypass -File ".\switcher.ps1"
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
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.
- 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.
- Run PowerShell as Administrator
- Check execution policy:
Get-ExecutionPolicy
# 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
netstat -an | findstr ":5252"
- Try a different unused port
- Initial release
- Basic RDP port changing and firewall config
- Multi-language support (EN/ES)
- User prompts and error handling
Contributions welcome!
- Fork this repo
- Create a branch:
git checkout -b feature/NewFeature
- Commit changes:
git commit -m "Add NewFeature"
- Push:
git push origin feature/NewFeature
- Submit a Pull Request
This project is licensed under the MIT License – see the LICENSE file for details.
diegofercri — https://diegofercri.dev