How to Give a group of users RDP access to a group of servers

Problem:

You are looking to give a group of users RDP access to a group of Windows 2012 Servers.

Requirements:

Firstly create a security group in Active Directory and add all the required users to it.

Solution:

In this example we will call the security group “Security1”.  Then, using the script below add the relevant server names.

function ListRemoteDesktopUsers{
$members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
$members}
$servers = "server1","server2","server3"  # enter server names here
$domain = "domain"                        # enter domain name here
$groupname = "Security1"              # enter the security group name here

Foreach ($server in $servers){
$computer = [ADSI]("WinNT://" + $server + ",computer")

$Group = $computer.psbase.children.find("Remote Desktop Users")
$RDPusers = ListRemoteDesktopUsers

if ($RDPusers -contains $groupname){
write-host "$server .. already has $groupname in Remote Desktop Users Group"}
else
{$Group.Add("WinNT://" + $domain + "/" + $group1)
}
}

Run the code and you should be all set.

2 comments

  1. I like the valuable information you provide with your articles.
    I will bookmark your blog and check again here regularly.
    I’m quite certain I will learn many new stuff here! Best of luck for the upcoming!

Leave a Reply

Your email address will not be published. Required fields are marked *

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