Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
as a starting point for this type of question go to technet.microsoft.com/en-us/scriptcenter/bb410849.aspx. –  tony roth Oct 23 '12 at 14:44
1  
And why are we using WMI/Powershell instead of GPOs/GPPs? –  HopelessN00b Oct 23 '12 at 15:55
    
@HopelessN00b good point! –  tony roth Oct 23 '12 at 16:41
add comment

1 Answer 1

up vote 2 down vote accepted

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)
share|improve this answer
    
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)} –  PeterX Nov 8 '12 at 0:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.