Ændre port nummer til fjernskrivebord win10, win11 RDP

Åben PowerShell som administrator og indsæt nedenstående kode. Koden sørger for at fjernskrivebord bliver “slået til”. Er test på windows10 og windows 11

husk at enable fjernskrivebord manuelt.

param (
    [int]$port = $(Read-Host "Please enter the new RDP port number")
)

# Set the registry value for the port
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Terminal*Server\WinStations\RDP-TCP\ -Name PortNumber -Value $port

# Enable Remote desktop
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -value 0

#Diable existing remote desktop rules
Set-NetFirewallRule -DisplayName "Fjernskrivebord - brugertilstand (TCP-In)" -Enabled False
Set-NetFirewallRule -DisplayName "Fjernskrivebord - brugertilstand (UDP-In)" -Enabled False

#Create custom remote desktop rules
New-NetFirewallRule -DisplayName "Fjernskrivebord brugerdefineret - TCP-In" -Action Allow -Description "Inbound rule for the Remote Desktop service to allow RDP traffic over TCP." -Direction Inbound -Enabled True -Group "Custom Rules" -LocalAddress Any -LocalPort $port -Protocol TCP -RemotePort Any
New-NetFirewallRule -DisplayName "Fjernskrivebord brugerdefineret - UDP-In" -Action Allow -Description "Inbound rule for the Remote Desktop service to allow RDP traffic over UDP." -Direction Inbound -Enabled True -Group "Custom Rules" -LocalAddress Any -LocalPort $port -Protocol UDP -RemotePort Any

# Restart the service to finalize the changes
# Use -Force as it has dependant services
Restart-Service -Name TermService -Force 

#Promt
Write-Host -Prompt "Ændringer er nu udført.Tryk enter."