Enable RDP with Powershell

 

Although the Remote Management is enabled by default starting with Windows Server 2012, the RDP access isn’t. To enable RDP with Powershell, you have two steps to perform:

  1. Enable the RDP Access
  2. Enable the inbound firewall rules

Here’s the code:

# 1. Enable Remote Desktop
(Get-WmiObject Win32_TerminalServiceSetting -Namespace root\cimv2\TerminalServices).SetAllowTsConnections(1,1) 
(Get-WmiObject -Class "Win32_TSGeneralSetting" -Namespace root\cimv2\TerminalServices -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0) 

# 2. Enable the firewall rule
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

The second line allows you to specify if you want to use NLA or not.