Using a Script to Add a Domain User to a Local Group

  • Section(s): Admin , Miscellaneous, Network
  • Published on Aug 31, 2006.
  • Last Modified on Aug 31, 2006.
  • Last Modified by Chris Sanders.
  • Rated 3.8 out of 5 based on 16 votes.
There are sometimes situations when you need to be able to script the process of adding a domain user to a local group on a machine. Here is a script that will do just that.
I ran into a scenario recently where I needed to add a domain group to the local administrators group of a large collection of workstations in my network. Rather than go around to all 500 of these machines individually I found a very useful little VBS script for getting this done.

option Explicit

Dim objGroup
Dim strComputer

On Error Resume Next

‘Variables you will want to change
strComputer = “.” ‘Computer is Local

‘Create Objects
Set objGroup = GetObject(”WinNT://” & strComputer & “/Administrators,group”)

‘Modify group memberships
objGroup.add(”WinNT://DOMAIN/GROUPNAME,group”)
Set objGroup = Nothing

Replace your variables, push this out via GPO, and voila! Enjoy!

***

Chris Sanders is the network administrator for one of the largest public school systems in the state of Kentucky. Chris's specialties include general network administration, windows server 2003, wireless networking, and security. You can view Chris' personal website at www.chrissanders.org.

About Chris Sanders

Chris Sanders is a network consultant for KeeFORCE, one of the most popular network consulting firms in western Kentucky. Chris is the author of the book Practical Packet Analysis as well as several technical articles. His personal website at www.chrissanders.org contains a great deal of information, articles, and guides related to network administration, network security, packet analysis, and general information technology.

Share this article


Article not looking right or info is missing? Let us know so that we can fix it: .


Receive all the latest articles by email!

Receive Real-Time & Monthly WindowsNetworking.com article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become a WindowsNetworking.com member!

Discuss your network issues with thousands of other network administrators. Click here to join!

Community Area

Log in | Register

Readers' Choice

Which is your preferred Help Desk solution?