MS-AZ-Q1:How to Change the Default RDP Port Number in the Azure Virtual Machine
Step-by-Step Guide to Changing the RDP Port in Azure VPS Machine -
Setup the VM Machine’s Firewall Rule for RDP
Create a Inbound Rules.
Setup Registry in the VM Machine for RDP (if needed)
Change a PortNumber Script from regedit
Setup the Azure Portal for Custom RDP
Create a Rule for RDP on NSG (Network Security Group)
Run Script for RDP Run Command
Change the Port Number Access from Connect Option from Left-side Nav Pane.
Step-01: Create a New Inbound Rule for the RDP Port
=>Control Panel\All Control Panel Items\Windows Defender Firewall\Advanced Settings.
=>Click on Right Button Mouse above Inbound Rules Option at the left side nevigation bar + Create New Rules & Select Port + Click Next Button

Step-02: Access the Registry Editor for RDP Port Number Access. (If Needed)
=> (Win+R) Open Run dialoge Box + `Enter regedit`
=>The following path:
``HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp``
=> Modify the PortNumber Entry or Create new DWORD (32-bit) Value.
=> Modify the Decimal value field.
=> Run `cmd` as Administrator + Enter following command for RDP services - net stop termservice && net start termservice
=> Restart the VM
=> For verifying RDP Services - "netstat -an | find “<new_port_number>"
Step-03: Azure Portal Configuration for RDP Services
=> From NSG, RDP Service Configuration - 1. Sign in to the Azure portal.
2. In Virtual Machines, select the VM that has the problem.
3. In Settings, select Networking.
4. In Inbound port rules, check whether the port for RDP is set correctly. The following is an example of the configuration: -
"Priority: 300
Name: Port_33091
Port(Destination): 33091
Protocol: TCP
Source: Any
Destinations: Any
Action: Allow"

=> From Operations Option + Click On Run Command + scroll Down and Click on SetRDPPort + Enter a value on RDPPORT Field then Click on RUN Button. Please follow the below pictures instructions accordingly.
Step-02: Access the Registry Editor for RDP Port Number Access. (If Needed)
=> (Win+R) Open Run dialoge Box + `Enter regedit`
=>The following path:
``HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp``
=> Modify the PortNumber Entry or Create new DWORD (32-bit) Value.
=> Modify the Decimal value field.
=> Run `cmd` as Administrator + Enter following command for RDP services - net stop termservice && net start termservice
=> Restart the VM
=> For verifying RDP Services - "netstat -an | find “<new_port_number>"
Step-03: Azure Portal Configuration for RDP Services
=> From NSG, RDP Service Configuration - 1. Sign in to the Azure portal.
2. In Virtual Machines, select the VM that has the problem.
3. In Settings, select Networking.
4. In Inbound port rules, check whether the port for RDP is set correctly. The following is an example of the configuration: -
"Priority: 300
Name: Port_33091
Port(Destination): 33091
Protocol: TCP
Source: Any
Destinations: Any
Action: Allow"

=> From Operations Option + Click On Run Command + scroll Down and Click on SetRDPPort + Enter a value on RDPPORT Field then Click on RUN Button. Please follow the below pictures instructions accordingly.
=> (Win+R) Open Run dialoge Box + `Enter regedit`
=>The following path:
``HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp``
=> Modify the PortNumber Entry or Create new DWORD (32-bit) Value. => Modify the Decimal value field. => Run `cmd` as Administrator + Enter following command for RDP services - net stop termservice && net start termservice => Restart the VM => For verifying RDP Services - "netstat -an | find “<new_port_number>"
Step-03: Azure Portal Configuration for RDP Services
=> From NSG, RDP Service Configuration - 1. Sign in to the Azure portal.
2. In Virtual Machines, select the VM that has the problem.
3. In Settings, select Networking.
4. In Inbound port rules, check whether the port for RDP is set correctly. The following is an example of the configuration: -
"Priority: 300
Name: Port_33091
Port(Destination): 33091
Protocol: TCP
Source: Any
Destinations: Any
Action: Allow"

=> From Operations Option + Click On Run Command + scroll Down and Click on SetRDPPort + Enter a value on RDPPORT Field then Click on RUN Button. Please follow the below pictures instructions accordingly.
=> From Operations Option + Click On Run Command + scroll Down and Click on SetRDPPort + Enter a value on RDPPORT Field then Click on RUN Button. Please follow the below pictures instructions accordingly.