Stanford Windows Infrastructure Documentation

Controlling Local Group Membership Via GPO

Often, it is desired to modify the memberships of local computer's built-in groups automatically. This can be done via a Group Policy Object (GPO) that is created and linked to the Organizational Unit (OU) that contains the computer objects.

This GPO can

  1. Point to computer startup script(s) that will check and update which users or groups are members of the machine’s local groups
  2. Use "Restricted Groups" policies.

For Example:

During the process to join a Windows computer to a domain, the group “Domain Admins” is added to the local machine's Administrators group. For systems administrators that are not Domain Admins, they are not granted local admin access by this action. This can be changed by one of the methods above

Scripts

Scripts currently available (in the SU domain)

To use scripts:

Using scripts for the above example:

AddAdmin.vbs would be linked in a GPO with parameters set to a group created for an organization's local administrators for machines .

Note: Some of the scripts need modification before they are run in another domain (see SU for example).

Feel free to create more scripts using these examples. If you create a new script that would assist others, please submit them for inclusion into this set.

Restricted Groups

To use restricted groups:

Using Restricted Groups for the above example:

Specify "Administrator", and your administration group to the Administrators restricted group settings

Note: If you have renamed the administrator account, use the new name or the local built-in admin will be removed (as the names don't match)

Note: This only works properly if all built-in administrator accounts of the machines in the OU have the same username. (You can use the administrator account rename feature in the GPO to make them all rename to the same value)

Script contents:

GPO Policy; Computer Configuration/Windows Settings/Scripts/Startup = AddAdmin.vbs, parameters = <domain>\<user>
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objGroup = GetObject("WinNT://" & objNetwork.ComputerName & "/Administrators,group")

 
For Each strArgument in Wscript.Arguments
                x = InStr(strArgument,"\")

                if X>0 Then

                                Domain_Name = Left(strArgument,x-1)
                                Admin_Name = Right(strArgument,Len(strArgument)-x)
                                DNPath = "WinNT://" & Domain_Name & "/" & Admin_Name
                               
                                On Error Resume Next
                                If Not objGroup.IsMember(DNPath) Then objGroup.Add(DNPath)
                                On Error Goto 0
                                End If     
                Next


Set objGroup = Nothing
set objNetwork = Nothing

GPO Policy; Computer Configuration/Windows Settings/Scripts/Startup = RemoveDomAdmin.vbs
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objGroup = GetObject("WinNT://" & objNetwork.ComputerName & "/Administrators,group")

DNPath = "WinNT://<domain>/Domain Admins"

On Error Resume Next
If objGroup.IsMember(DNPath) Then objGroup.Remove(DNPath)
On Error Goto 0

Set objGroup = Nothing
set objNetwork = Nothing

GPO Policy; Computer Configuration/Windows Settings/Scripts/Startup = AddUser.vbs, parameters = <domain>\<user>
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objGroup = GetObject("WinNT://" & objNetwork.ComputerName & "/Users,group")

For Each strArgument in Wscript.Arguments
     x = InStr(strArgument,"\")
     if X>0 Then
          Domain_Name = Left(strArgument,x-1)
          Admin_Name = Right(strArgument,Len(strArgument)-x)
          DNPath = "WinNT://" & Domain_Name & "/" & Admin_Name

          On Error Resume Next
          If Not objGroup.IsMember(DNPath) Then objGroup.Add(DNPath)
          ON Error Goto 0

          End If
     Next

Set objGroup = Nothing
set objNetwork = Nothing

GPO Policy; Computer Configuration/Windows Settings/Scripts/Startup = RemoveDefaultUsers.vbs
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objGroup = GetObject("WinNT://" & objNetwork.ComputerName & "/Users,group")

DNPath = "WinNT://<domain>/Domain Users"

On Error Resume Next
If objGroup.IsMember(DNPath) Then
     objGroup.Remove(DNPath)
     DNPath = "WinNT://NT Authority/Authenticated Users"
     objGroup.Remove(DNPath)
     DNPath = "WinNT://NT Authority/INTERACTIVE"
     objGroup.Remove(DNPath)
     End If
On Error Goto 0

Set objGroup = Nothing
set objNetwork = Nothing

Created: December 1, 2003 by Ross Wilper
Last modified: January 05, 2006 by Ross Wilper
©2006 Trustees of the Leland Stanford Junior University
Information Technology Systems and Services