PowerShell

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"}

Unbenannt.JPG

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

Unbenannt.JPG

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

4 replies »

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 )

Google+ photo

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

Twitter picture

You are commenting using your Twitter 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.