Search This Blog

Thursday, August 23, 2012

Enable Remote Desktop from PowerShell/WMI

The other day I had to connect to my dev box at work from home but I realized that I did not enable remote desktop on my machine at work so I could not connect to it. However, I knew that I have a remote desktop access to another machine in my office so I connected to it and tried to see if there is any way I can enable remote desktop on my dev box via WMI interface using PowerShell. I looked up online and found bits of information here and I enabled remote desktop but somehow I could not still remote desktop to my dev box. When I came to work next day I learned that I also had to enable firewall setting for remote desktop service. So here is my post on how to enable remote desktop on Windows 8.
First, we need to keep our credential information so that we do not have to enter it every time we connect to the remote machine.
$cred = Get-Credential
Then, let us check if remote desktop is enabled. This will tell us if we need to enable it.
PS C:\temp> Invoke-Command -computername dev-pc -scriptblock {(gwmi -class win32_terminalservicesetting -namespace "root\cimv2\terminalservices").allowtsconnections} -Credential $cred
If we need to enable it, run the following command.
PS C:\temp> Invoke-Command -computername dev-pc -scriptblock {(gwmi -class win32_terminalservicesetting -namespace "root\cimv2\terminalservices").setallowtsconnections(1)} -Credential $cred
Then, run the following one to make sure that authentication is required for remote desktop access.
PS C:\temp> invoke-command -computername dev-pc -scriptblock {(gwmi -class win32_tsgeneralsetting -namespace "root\cimv2\terminalservices").setuserauthenticationrequired(1)} -Credential $cred
The above step basically enables Remote Desktop on my dev-pc but the trouble I had was that I still could not connect to my dev box because of firewall so we need to take care of that as well. To do that, we will need to run one more command.
PS C:\temp> invoke-command -computername dev-pc -scriptblock {netsh advfirewall firewall set rule group="remote desktop" new enable=Yes } -Credential $cred
Once we execute the last command, we are now able to remote desktop to remote computer.
Lastly, let me put two websites that I got the above scripts from to enable remote desktop.

10 comments:

  1. A couple of posts back I mentioned that I was working on a configuration library for Server 2008 R2 Core and Hyper-V Server R2 and this includes checking and setting the configuration for remote desktop.

    remote desktop software

    ReplyDelete
    Replies
    1. I have also worked on to create some script for this have a look : http://aikitsupport.com/checking-and-enabling-remote-desktop-with-powershell/

      Delete
  2. I enjoy the them here. Can it be downloadable anywhere?
    Thanks!

    Here is my web-site danon jewellery england

    ReplyDelete
  3. Aωesome artісle.

    Αlѕo νisіt my ωeb ѕite :
    : hotmail sign up

    ReplyDelete
  4. Useful information. Fortunate me I found your website by chance, and I'm stunned why this coincidence didn't came about earlier!

    I bookmarked it.

    my web site; xerox 8560mfp driver

    ReplyDelete
  5. Sometimes the easiest means to deleted installed control series is to copy and paste the afflicted section to notepad, tidy up the text you desire
    protected, then copy and insert it back.

    Here is my blog ... vintagefordfacts.blogspot.com

    ReplyDelete
  6. I truly adored this great guide. Please continue this outstanding operate.


    My blog post xerox phaser 8560 toner

    ReplyDelete
  7. It's fantastic that you are getting ideas from this post as well as from our dialogue made at this place.

    Also visit my web blog - hultquist jewellery uk

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. I gotta favorite this website it seems very helpful .
    Titanium Pendants UK

    ReplyDelete