Jump to content


  • 0
capriguy84

Add users to a RDP group based on hostname

Question

Hi Guys,

 

I would like to add domain users to be able to log on via RDP to their desktop via script or GPO. Basically, all our desktops are named after the user who uses it.

 

Dersktop=sjobs-xp1, sjobs-ws1 and Username=sjobs

 

Can you guys advise me how can I achieve this? Any scripting ideas on windows? We also just started using SCCM, so anything there can also work.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Ok. so I wrote a powershell script myself and here it is if someone comes looking for similar request.

 

# Script to add a domain user to a Remote Desktop users group on the local PC.

$computerName = gc env:computername
$userName = $computerName.split("-")[0]
$Domain = gc env:USERDNSDOMAIN
$localGroupName = "Remote Desktop Users"

if ([adsi]::Exists("LDAP://CN=$userName,OU=PEOPLE,OU=Accounts,DC=laurion,DC=corp"))
{
 $adsi = [ADSI]"WinNT://$ComputerName/$localGroupName,group"
 $memberList = $adsi.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

 foreach($member in $memberList)
 { Write-Host "Member is $member"
if(!$member -eq $userName)
{  
   	$adsi.add("WinNT://$Domain/$userName,group")
   	Write-Host "User $Domain\$userName is now member of local group $localGroupName on $computerName."
} else
{
   	Write-Host "User already exists in the group."
}
 }
} else
{
 Write-Host "User does not exist in AD domain."
}

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.