Enabling Remote Desktop remotely with PowerShell

Consider the following scenario: There’s a switched on client computer in a branch office and you want to connect to that computer via remote desktop. Remote desktop is disabled by default on all Windows operating systems. There’s no user logged on this client computer and no one can help you to enable remote desktop. What do you do then? The answer is: Do some PowerShell remote actions!

The following only works if WinRM is enabled. Since Windows Server 2012 WinRM is enabled by default on all Windows server operating systems, but not on client operating systems. To enable WinRM on your client computers see: Group Policies: Enabling WinRM for Windows Client Operating Systems (Windows 10, Windows 8, Windows 7)

Enabling Remote Desktop with PowerShell Remoting

It is assumed that WinRM is enabled on the target host. I have two computers: azdc01 and client01. On client01 remote desktop is disabled.  Now I run the following command to enable remote desktop on client01:

Invoke-Command -ComputerName client01 `
{Set-ItemProperty `
-Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'`
-Name "fDenyTSConnections" -Value 0; `
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"}


Finally, let’s do some checks. Port 3389 should be open now, right?


From now on you are able to establish a remote desktop connection to your remote host.

7 replies »

  1. How can we put theese codes into a menu to have the possibility to return to main menu? Like:
    Main menu:
    1 – Type Computer Name
    Result: Remote desktop enabled, type 1 to return to main menu or any key to exit

    2 – Test RD port 3389
    Result: Remote desktop works, type 1 to return to main menu or any key to exit
    0 – Exit


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.