You have just set up a Windows Server and realise that you need to start a remote desktop session to install some software for example, but you forgot to configure Remote Desktop.

Although remote desktop is disabled by default fortunately on Windows Server from 2012 onwards PowerShell Remoting is enabled by default. So with just a couple of lines of PowerShell you can enable Remote Desktop. Using Invoke-Command we are going to run a couple of commands (they could be combined in the same ScriptBlock but for clarity I have separated them).

Invoke-Command -ComputerName server01 -ScriptBlock {<br />
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'<br />
-Name fDenyTSConnections -Value 0}</p>
<p>Invoke-Command -ComputerName server01 -ScriptBlock {<br />
Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'}

The first modifies a registry key to toggle the flag that is set to Deny TS connections and the second modifies the Windows firewall to enable the built-in rule to open the port for RDP.

To see a video of me explaining how to do this please visit TechSnips.io