Enable Remote Desktop Using PowerShell
Open an elevated Windows PowerShell session and run the following commands. This first one creates the fDenyTSConnections value and sets it to 0 (off). This makes sense, because we don’t want to deny Terminal Services (TS) connections.
1 2 |
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0 |
Set Network Level Authentication for Remote Desktop
1 2 |
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\ WinStations\RDP-Tcp'-Name UserAuthentication -Value 1 |
Setting Firewall Rules :
1 |
Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True |
Since you’re using Server 2012 which means PowerShell remoting is enabled.
1 2 |
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0 |
1 2 |
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1 |
1 |
Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True |
you can throw all of this in the script block of Invoke-Command to remotely enable RDP
1 2 3 4 5 6 7 |
Invoke-Command -ComputerName ThatLazySRV01 -ScriptBlock { Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0 Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1 Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True } |
Be First to Comment