How to Enable or Disable Remote Desktop Connection (RDP) on a Computer Using PowerShell
Problem
In this blog post, we will walk you through how to enable or disable Remote Desktop Connection (RDP) on a computer using PowerShell.
For example, if you disable RDP on your computer, the other computer won’t be able to perform RDP to your computer.
Solution
To enable or disable RDP, you have to change registry key value which is located at HKLM:\System\CurrentControlSet\Control\Terminal Server
path. You can do it using PowerShell, for example.
Using Set-ItemProperty Cmdlet to Change Registry Value
To enable RDP, we must change fDenyTSConnections
value to 0 using Set-ItemProperty
cmdlet.
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
Optionally you can also execute following script after executing above script. This way, firewall rule for Remote Desktop is also enabled.
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Similarly, to disable RDP you have to change fDenyTSConnections
value to 1 using Set-ItemProperty
cmdlet.
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 1
Then executing following script to disable firewall rule for Remote Desktop which is optional,
Disable-NetFirewallRule -DisplayGroup "Remote Desktop"
Conclusion
To enable or disable RDP to a computer, you have to change fDenyTSConnections
registry value which is located at HKLM:\System\CurrentControlSet\Control\Terminal Server
. You can use PowerShell to change the value.