When we have to do that, most of the times we try to change a registry key that will enable or disable RDP connectivity on a Windows Server or desktop. But sometimes, modifying the registry is not always convenient. For those out there who thinks there should be much easier way, this post is for them
You can enable RDP on a remote host by simply running the below two lines.
$tsobj = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace Root\CimV2\TerminalServices -ComputerName SERVER01$tsobj.SetAllowTSConnections(1,1)
Or, if you want to disable it…
$tsobj
= Get-WmiObject
-Class
Win32_TerminalServiceSetting
-Namespace
Root\CimV2\TerminalServices
-ComputerName
SERVER01$tsobj.SetAllowTSConnections(0,0)
and waht about if you want to check if its currently enabled or disabled?
$tsobj
= Get-WmiObject
-Class
Win32_TerminalServiceSetting
-Namespace
Root\CimV2\TerminalServices
-ComputerName
SERVER01$tsobj.AllowTSConnections
If you are wondering what are the 2 arguments for SetAllowTSConnections function, let me answer to that:
- The first one represents AllowTSConnections(0 – disable, 1 – enable)
- The second one represents ModifyFirewallException (0 – don’t modify firewall rules, 1 – modify firewall rules)
Till next time!