Windows servers are using port TCP 3389 for Remote Desktop Protocol as a default port. In some situations, as when you wish to obtain a more secure environment, changing the default remote access port can be useful.

Important note: Before we continue, you need to verify if the port that you want to assign has been added into allowed port in Firewall.

Using Registry Editor

To change the Remote Desktop (RDP) port, do the following.

1. Open the Registry Editor app, right click on Windows Menu and click “Run” menu, and type “regedit” without quote.

2. Once the Regedit (Registry Editor) window is open. Go to the following Registry key.

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp

Find the key with name “PortNumber” on the right window.

3. Double Click the “PortNumber” Key and click on “Decimal” choice. In Value Data, change the number with the port that you want to use.

4. Click OK to save the changes.

Using PowerShell Script.

I’ve also created a PowerShell script and uploaded on My Github Page. You can find the script on this link
.ps1

# Check if the powershell is running as Admin

$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
If (!( $isAdmin )) {
Write-Host "-- Restarting as Administrator" -ForegroundColor Cyan ; Start-Sleep -Seconds 1
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}

#Enter the port that you want
Write-Host "Warning !!!, This script will modify your registry setting, you may need to backup your system" -ForegroundColor Red
Write-Host "`n"
Write-Host "This is the script to change the Remote Desktop Port" -ForegroundColor Green
Write-Host "`n"
$NewPort = Read-Host "Enter the Remote Desktop Port that you want:"

$RegistryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
$KeyName ="PortNumber"

try {
Set-ItemProperty -Path $RegistryPath -Name $KeyName -Value $NewPort -Force | Out-Null
Write-Host "RDP Port has been changed, please restart your computer to apply the changes"
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
catch {
Write-Host "Error. Please check or contact your administrator" -ForegroundColor Red
}