0

How do I administer local groups on a remote server with PowerShell and WMI? For example, I would like to add and remove domain AD groups from the "Remote Desktop Users" group.

This article provides a script for listing users while this article provides a bit more detail on the Get-WMIObject (GWMI) and Set-WMIObject (SWMI) cmdlets, however I'm unsure how to proceed with updating the group membership.

3
  • as a starting point for this type of question go to technet.microsoft.com/en-us/scriptcenter/bb410849.aspx. Commented Oct 23, 2012 at 14:44
  • 1
    And why are we using WMI/Powershell instead of GPOs/GPPs? Commented Oct 23, 2012 at 15:55
  • @HopelessN00b good point! Commented Oct 23, 2012 at 16:41

1 Answer 1

3

ADSI is your friend

$server = "somesServer" $domain = "someDomain $group2add = "group2add" $localGroup = [adsi]"WinNT://$server/administrators,group" $domainGroup = [adsi]"WinNT://$domain/$group2add,group" $localGroup.Add($domainGroup.path) 
1
  • Ok thanks. I also worked out how to list the members from this: $localmembers = @($localGroup.psbase.Invoke("Members")) $localmembers | foreach {$_.GetType().InvokeMember("AdsPath","GetProperty",$null,$_,$null)} Commented Nov 8, 2012 at 0:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.