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.


ADSI is your friend

$server = "somesServer"
$domain = "someDomain
$group2add = "group2add"
$localGroup = [adsi]"WinNT://$server/administrators,group"
$domainGroup = [adsi]"WinNT://$domain/$group2add,group"
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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