Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts Network Monitor
Monitor servers, workstations, devices and applications in your network

Quicklinks


Scripts to manage Local Groups

Adding a User to a Local Group
Creating a Local Group on a Computer
Deleting a Local Group
Deleting a User from a Local Group
Enumerating Local Groups and Their Members
Listing All the Local Groups a User Belongs To

Adding a User to a Local Group


Adds a user (kenmyer) to the local Administrators group on a computer named MyComputer.
strComputer = "MyComputer"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")
objGroup.Add(objUser.ADsPath)

Creating a Local Group on a Computer


Creates a local group named FinanceUsers on a computer named MyComputer.
strComputer = "MyComputer"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("group", "FinanceUsers")
objUser.SetInfo

Deleting a Local Group


Deletes a local group named FinanceUsers from a computer named MyComputer.
strComputer = "MyComputer"
Set objComputer = GetObject("WinNT://" & strComputer & "")
objComputer.Delete "group", "FinanceUsers"

Deleting a User from a Local Group


Removes kenmyer from the local Administrators group on a computer named MyComputer.
strComputer = "MyComputer"
Set objGroup = GetObject("WinNT://" & strComputer & "/Adminstrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")
 
objGroup.Remove(objUser.ADsPath)

Enumerating Local Groups and Their Members


Returns a list of local groups (and their members) found on a computer named atl-win2k-01.
strComputer = "atl-win2k-01"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    Wscript.Echo objGroup.Name 
    For Each objUser in objGroup.Members
        Wscript.Echo vbTab & objUser.Name
    Next
Next

Listing All the Local Groups a User Belongs To


Returns a list of all the local groups on the computer atl-win2k-01 that a user named kenmyer belongs to.
strComputer = "atl-win2k-01"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    For Each objUser in objGroup.Members
        If objUser.name = "kenmyer" Then
            Wscript.Echo objGroup.Name
        End If
    Next
Next